Search code examples
gitjenkinsgerritgerrit-triggerklocwork

Jenkins + Git/Gerrit + Incremental Klocwork Scans


So we have a Jenkins server, we use gerrit to code review our develop branch, we have the Klocwork community plugin installed.

Our Jenkins spawns builds that are +1 verify votes on Gerrit patchset pushes.

Currently we only Klocwork scan every few hours on our merged Develop branch and i'd like to instead perform incremental/diff scans on every patchset push to prevent bad code from making it through in the first place.

So i setup the Klocwork plugin in our Jenkins build config, but when I add an incremental scan build step, since we're using Git it requires me to enter in a Previous Commit SHA. I've tried everything but without success.

Ive tried $GIT_PREVIOUS_SUCCESSFUL_COMMIT, but it didnt seem to work and seemed wrong to us anyways because the previous Jenkins commit could be based off a completely different branch(parent) so the Diff of whats changed wouldnt make sense.

We then had the idea that the previous commit it should be comparing against is the Parent SHA, not necessarily the last Jenkins build which may or may not be on the same branch.
So I added a windows batch file build step before our build that gets the Parent SHA1 using git log, pipes it to a file, and then uses SET to set an env variable like PARENT_COMMIT with that SHA1 which i then tried using %PARENT_COMMIT% in the "Previous Commit SHA" area of Klocwork incremental and the build fails because it cant find the var.

I feel like this is a common thing, so the solution must be stupid simple and we're making it way more complex than it needs to be, but i cannot for the life of me find any documentation that tells me what the hell to put in this box.

Please help :)

Thanks!


Solution

  • Are you using Jenkins gerrit-trigger plugin to trigger the builds, right? So you could try to use $GERRIT_PATCHSET_REVISION^, which is the first parent of the SHA1 defined by the environmental variable GERRIT_PATCHSET_REVISION.