Misc Tech Notes

Sön 27 Mars 2016

Code review and automation

Posted by Peter Reuterås in Tips   

This is the second post about automation. This time I'll write about Jenkins and ShellCheck and automatic code review. I'm currently working on a tool that does automatic actions on supplied files to analyze if they might be malicious or not. Since the script is over 600 lines of bash script in the main file I started looking for a tool to validate and review bash code. I found a couple of tools but settled for ShellCheck. The code for ShellCheck can be found on Github. There is also a great wiki which explains the warning messages and proposes solutions. I've found this to be a great resource to learn to write better bash scripts in general. The code will hopefully be more robust and more stable. I've just started the code review and should do much more to make the code rugged.

When I code in Vim ShellCheck will check the code on saves and I can fix any warnings about bad syntax. Sometimes however I use different editors or make a quick change and miss a warning. To make sure that I catch this warnings and get a notification I had to find automated way to get notified. Since ShellCheck can output the results of a check in Checkstyle format it was easy to integrate it in Jenkins. That way I get notifications on ShellCheck warnings if bad code is checked in to Git.

Below is the start page of my Jenkins installation which shows the projects where I have some tests enabled. For most of them I really should add better and more thorough tests. Thats on the todo list... In addition to checking bash syntax with ShellCheck I use pylint to check Python code.

Picture of first page in my Jenkins installation