I’ve successfully used the ignore command to skip unnecessary builds for my hugo sites until now. Today I pushed an update to one of my sites, and the build was skipped because of the ignore command. I tried several other updates, changing different files, and the build was still skipped.
After adding an echo command to print both $CACHED_COMMIT_REF and $COMMIT_REF to the console, what I was suspecting has been confirmed: $CACHED_COMMIT_REF and $COMMIT_REF are the same. How could this be?
When a build runs without cache, CACHED_COMMIT_REF will be the same as the COMMIT_REF.
What does that mean? When is the cache created, when is it cleared, what does it cache? I haven’t pushed updates to my sites in a while (couple of months). Could it be that the cache gets cleared, and when this happens CACHED_COMMIT_REF is gone?
How can I make my ignore command work again?
Hi, @MaxM. I would just add a check to your build.ignore command to always force the build to run if the CACHED_COMMIT_REF and COMMIT_REF match like so:
if [ "${COMMIT_REF}" == "${CACHED_COMMIT_REF}" ] ; then false ; else git diff --quiet $CACHED_COMMIT_REF $COMMIT_REF . ../themes/microsites ; fi
This is just adding a conditional wrapper around you current build command that says this:
if the two refs match run the command false (which will return a 1 exit code and continue the build)
otherwise run the normal build ignore (which returns a 1 exit code if there is a difference continuing the build and instead exiting if no difference exits)
The format above is:
if [ "${COMMIT_REF}" == "${CACHED_COMMIT_REF}" ] ; then false ; else <ORIGINAL COMMAND HERE> ; fi
If that doesn’t work or if there are other questions, please let us know.
Thanks @luke, that’s of course the solution, I should have thought about it right away!
Still, I think it would make sense to update the docs here: Ignore builds | Netlify Docs to use as example the ignore command that uses the if statement - reading that page is easy to assume that CACHED_COMMIT_REF is never purged.