Passing Hudson BUILD_NUMBER to Sonar Plugin

Sonar is a great source code analysis tool that integrates through its plugin neatly into the Hudson continuous integration server. One major feature of Sonar is the module called “Time machine” where you can review the progress of the quality metrics for your project over time. However, to see this progress, it is necessary to tag the version of the Sonar run dynamically, otherwise, the new run “overwrites” the previous results. Sonar does not really discard the old results, but to fetch the older outcomes in the Time machine view is quite tedious.

So, what you need to do is really simple:

  1. Pass the BUILD_NUMBER to the Maven call in the field “Additional properties”
  2. Have the Sonar Plugin insert a variable for replacement in the generated POM file

In my example the replacement variable is called “version” but you can name it as you want.

Pass a variable Version Number to Hudson Sonar Plugin
Pass a variable Version Number to Hudson Sonar Plugin

With the shown configuration Sonar will store the results under “hudson-##” where ## is the current iteration of the Hudson build cycle. Of course it is also possible to pass other information, like the BUILD_ID or JOB_NAME. A listing of available Hudson environment variables can be found here.

Andreas

One Reply to “Passing Hudson BUILD_NUMBER to Sonar Plugin”

  1. Hello Andreas !
    Thank you for this tip , I’ve just set up those variables, I can now follow which hudson build has the shown metrics !

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.