0

We are currently using Bamboo for our build tool and one of our stages contains a task to run Sonar analysis.

It works great except for the fact that results are published for both master and feature branches. Of course this means that if we build a branch then results will override the existing ones.

We have looked into Auto Branch in the Sonar task but we don't want a large number of branch projects in Sonar so this is a no-go for us.

How else can we selectively run Sonar analyses depending on the branch? I heard that using a property in our Maven pom.xml could work, I wonder if anyone has an example of that?

mchinaloy
  • 1,444
  • 3
  • 25
  • 42

1 Answers1

0

I add the -Dsonar.projectVersion=${bamboo.repository.branch.name} at runtime. That adds the branch as the project version.

I am using sonar-runner to execute the sonar analysis so since you're using maven, your mileage may vary - in other words convert that to whatever the maven version of that argument is.

So when I run the sonar-runner task I include that -D argument on the command line. Even running it with maven you should be able to pass it in on the command line. Whatever branch is building that's the one that will show up on the SonarQube dashboard.

gjones
  • 89
  • 9