sonar.newCode.referenceBranch not working when pass as additional parameter in Prepare Analysis

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension):- 9.9.3 (Enterprise edition)
  • how is SonarQube deployed: zip, Docker, Helm : Zip
  • what are you trying to achieve:- Set sonar.newCode.referenceBranch as parameter in Prepare Anlysis
  • what have you tried so far to achieve this:- Set and try to run the build pipeline

We are using Azure DevOps Server and Sonar qube 9.9.3 for analysis. we have many projects which are using common task for Prepare Analysis. Currently all projects using default settings at global level which is set to 30 days for new code.
I try to pass the sonar.newCode.referenceBranch to our main branch for all projects in our common task as sonar.newCode.referenceBranch=master
This throws an error which is “java.lang.IllegalStateException: Reference branch set with ‘sonar.newCode.referenceBranch’ points to the current branch ‘master’”

I tried the same thing at project level through UI and set reference branch to master, that works as expected. Issue is we have more than 200 different projects and setting at project level is time consuming and difficult for maintenance. Is there any way we can set it globally as default for all projects and override where needed.

Also is it possible to set up the reference branch to target branch in case of Pull request rather than master always. Most of cases it will be master but few projects we have where PR goes to other brnaches first then to master

Do not share screenshots of logs – share the text itself (bonus points for being well-formatted)!

Thanks
Sunil

Hi,

When analyzing the main branch, you set the reference to main? That’s… not gonna work.

This shouldn’t need to be set manually, it should be read automatically from the environment.

 
HTH,
Ann