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

Thanks Ann for your response. What about analysis running on feature branches which are initially created from master branch. How can I set up this in property file master as reference branch. I can’t find this setting at global level to set by default ref branch as master.

And what will happen if we run the analysis through pipline on master branch. Can it be configured to last analysis on mastr branch

Also in case I wanted to chnage it to some other permamnent branches like develop. How you acn set this up for a project.

Hi,

Okay, yes. You’ll want to set the reference branch manually and explicitly.

 
HTH,
Ann

So that there is no way I can use sonar.newCode.referenceBranch=master as default param.

Hi,

Well… not for your master branch. No.

 
Ann

I think i got confused. We are trying to analyse our feature branches and few other branches and would like to keep master branch as reference branch. Sometime our feature branches does stay longer than 90 days before merging to master

Hi,

For your non-master branches, you could certainly use sonar.newCode.referenceBranch=master.

 
HTH,
Ann