Hugo: ERROR: not a git repository, when build from CI/CD
While setting up my CI/CD pipeline for this Hugo based site i have bumped into the following build error that took me a while to fully get rid of:
#10 [6/6] RUN hugo -d /usr/share/nginx/html/ #10 1.485 Building sites … ERROR 2020/06/02 20:23:42 Failed to read Git log: fatal: not a git repository (or any of the parent directories): .git #10 1.488 Total in 7 ms #10 1.488 Error: Error building site: "/usr/share/blog/content/_index.md:11:1": failed to extract shortcode: template for shortcode "ticks" not found #10 ERROR: executor failed running [/bin/sh -c hugo -d /usr/share/nginx/html/]: runc did not terminate sucessfully
As you might be aware of, the Hugo quickstart uses a git method to install the theme. This is fine, and also a very nice method to keep your theme up to date.
However if you are building from inside a CI/CD pipeline you might realize that these
.git folders and their content are NOT committed into your repo. It would me messy if it would, so this is also fine.
The actual error is actually triggered by an option in your
config.yaml (or .toml, .json):
from the Hugo configuration docs:
Enable .GitInfo object for each page (if the Hugo site is versioned by Git). This will then update the Lastmod parameter for each page using the last git commit date for that content file.
The easy way around this is to manually add the
lastmod parameter to the frontmatter for each edit (documented here).
Unfortunatilly due to the way files are moved around when building docker images it is not reliable to use any of the other methods as far as i’m aware. Please let me know in the comments below in case you find a better way to do it.