Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I populate the sonar.projectVersion in sonar.properties?

I have a jenkins based ant build project which uses the "Invoke Standalone Sonar Analysis" build step to call sonar. The build and the analysis both work fine. However what we really want to do from a reporting perspective is to compare builds in terms or code quality over a range of version numbers.

We were thinking of using the Jenkins generated build number as the sonar.projectVersion. Is there a way I can extract that information from Jenkins and use this as my sonar.projectVersion?

If that is not possible is there any other sequence number that we can use?

like image 641
Swapnonil Mukherjee Avatar asked Mar 07 '14 10:03

Swapnonil Mukherjee


1 Answers

Sonar should use the Maven project version by default for this number. So this may actually be the best version number to use. You will need to make sure your maven versions are updated correctly with new releases.

If you want to use the Jenkins job number, you can do so by passing it through the mvn sonar command, something like:

mvn sonar:sonar -Dsonar.projectVersion=$BUILD_NUMBER 

When using ANT. You can define a property in the build.xml file like so:

<property name="sonar.projectVersion" value="${projectVersion}" />

then when running the ant command from Jenkins pass it through:

ant -DprojectVersion=$BUILD_NUMBER

This page has details

like image 151
cowls Avatar answered Nov 09 '22 18:11

cowls