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

11,292

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

Share:
11,292

Related videos on Youtube

Bala
Author by

Bala

Software Architect, Developer based out of Kolkata, India.

Updated on September 16, 2022

Comments

  • Bala
    Bala over 1 year

    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?

  • Bala
    Bala about 10 years
    My project is ant based. So this will require me to use maven which is not an option for me.
  • cowls
    cowls about 10 years
    Im sure there is a way to pass paramters through with Ant. I have added some info