All we have 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 adviced to check for 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.
Be First to Comment