Shellcheck in Jenkins

All we’ve written shell scripts. And at the speed we need to deploy is easy to make mistakes (beginner mistakes). So I decided to integrate Shellcheck in Jenkins so that when a commit is done the CI drops a complete shell check analysis of the code. A test in your CI could be something like:

grep -rIl '^#![[:blank:]]_/bin/(bash|sh|zsh)' \ --exclude-dir=.git --exclude=_.sw? \
     | xargs shellcheck

The exclude switches are useful for git and vim users respectively. Is strongly advised to check for the availability of shellcheck in your build agent before the test. I use to wrap my test code with some kind of check like so:

if which shellcheck ; then

# Do your tests here

`fi`

There are other nice ways of performing automatic tests using make as your procedure executor. I will talk about that in later posts. Happy testing! Edit: A nice snippet for your Makefiles could be like so.


← Blog