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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With