We use Understand every day on our own code as part of our Continuous Integration(CI) process. Each time an engineer does a git commit we test that their changes builds on all of our supported platforms, and then we test that they are adhering to our internal coding guidelines using CodeCheck. We use Jenkins to manage this. Here’s a brief walkthrough of our Jenkins setup with Understand and Codecheck, hopefully it can help you with yours.
1. We set up our project as a Freestyle project
2. Once you’ve configured the triggers, version control and build environment for your project, select Execute Shell (or batch command on Windows)
3. And here’s the code we’re calling in the shell.
#!/bin/bash -x
UNDEXE=$WORKSPACE/bin/macosx/und
PROJDB=$WORKSPACE/src/understand/understand-macosx.und
GITREV=$(git rev-parse HEAD)
$UNDEXE -db $PROJDB analyze -changed
$UNDEXE -db $PROJDB codecheck -exitstatus -showexcluded -htmlsnippets -showdetaillog -flattentree -gitfiles $GITREV SciTools $WORKSPACE/codecheck_output
We’ll walk through each step and explain it.
#!/bin/bash -x
The -x after the bash instruction outputs the commands being run in addition to the output. This is useful for debugging.
UNDEXE=$WORKSPACE/bin/macosx/und
This sets the location of the und executable. If you aren’t familiar with und, it let’s you access many of Understand’s features from the command line - this support article is a great place to learn about it…
PROJDB=$WORKSPACE/src/understand/understand-macosx.und
And this is the location of our understand project directory. Since this Understand project is the source code for Understand this might be a little confusing. Just point it at your project, e.g. myProject.und
GITREV=$(git rev-parse HEAD)
Our goal here is to look at the changes that were done in the last commit, so this steps gives us the revision number of the last commit
$UNDEXE -db $PROJDB analyze -changed
This script assumes you already have an Understand project built, so we’re just going to analyze any files that have changed in it to make sure it is up to date.
$UNDEXE -db $PROJDB codecheck -exitstatus -showexcluded -htmlsnippets -showdetaillog -flattentree -gitfiles $GITREV SciTools $WORKSPACE/codecheck_output
And finally, the last but most important line of the shell script. This command runs Codecheck against the project. Codecheck has a lot of command line options available to it which you can see by running und help codecheck, but here’s a brief overview of the ones we are using:
-exitstatus Return a not zero value if there are violations reported, i.e. fail the jenkins job
-showexcluded In our case we are interested in seeing the violations surrounding the modified areas of the code so show them as well
-htmlsnippets Save the output as an html folder that include a few lines of code with each violation
-showdetaillog Add extra details to the Jenkins output for debugging
-flattentree Show the full file name for each file, don’t build a tree
-gitfiles Here we specify the revision to look at. Understand will get the files and lines modified in that commit and focus the CodeCheck inspection there.
SciTools is the name of our CodeCheck Configuration, specify whatever configuration you’ve created in CodeCheck
codecheck_output Is the output directory where our results will be saved.
4. There are several files created, but the one we care about for this is called pages/intro.html and we’re going to email that file to the engineer if there are violations. We use a base Jenkins plugin called Email Extension that let’s us specify extra details about the email, including embeding files.
So we add the email as a post-build action
We’re happy with the defaults for notifying the engineer that did the commit, and we just change the Subject and Body to include the file
And that’s it. Now whenever one of our engineer’s checks in a commit that doesn’t follow our coding standard that will get an email looking like this:
Now you can set up your own standard! Let us know if you get stuck or have any questions - you can always reach us at [email protected]