Knowledge Base

Preserving for the future: Shell scripts, AoC, and more

Shell snippets for CI jobs

In some CI (continuous integration; i.e., Gitlab runners, Jenkins jobs, et al) shell jobs that I wrote, I finally turned some useful things into parameters. With code being checked into source control, I would hate to have to update the scm just to re-enable pipefail. But updating the invocation of a shell script in the CI is easy! So now I have this:

echo " $@ " | grep -qE " -v | --verbose " && set -x || :
echo " $@ " | grep -qE " --pipefail " && set -oe pipefail || :

It is important to wrap the $@ (all parameters excluding $0 which is the name of the invoked command) with spaces, so that the checks work correctly. Also, the logical or || with a shell no-op : is important for those pipefail-enabled situations!

Share any small snippets that you use to make your life easier in your CI jobs!

Comments