Unexpected Behavior sonar.newCode.referenceBranch

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension) 10.6 (92116)
  • how is SonarQube deployed: zip
  • what are you trying to achieve
    When executing SonarScanner 5.0.1.3006 I am passing in the new code reference branch parameter and it is not showing up as the new code reference branch within the project.

Example:
Executing “sonar-scanner-5.0.2.3006/bin/sonar-scanner -Dsonar.host.url=*** -Dsonar.token=**** -Dsonar.newCode.referenceBranch=develop -Dsonar.branch.name=feature-branch”

Navigating the UI Project → Project Settings → New Code → Branch. I expect the following table:

Branch Setting Action
feature-branch development

Instead I get the following:

Branch Setting Action
feature-branch Project setting

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

Hi @msemich,
The sonar.newCode.referenceBranch parameter allows you to customize the reference branch for a specific analysis.

When analyzing a branch for the first time, this parameter lets you define which branch will be used as a comparison point to identify new code. This feature is particularly useful when the branch being analyzed doesn’t yet exist in SonarQube.

However, it’s important to note that this parameter doesn’t modify the global configuration of the reference branch in the SonarQube user interface. To change the default reference branch for all future analyses, you need to go to your project or organization settings.

For more information on the parameter hierarchy and how they interact, consult Analysis parameters hierarchy

Thank you for replying. Are you saying that “-Dsonar.newCode.referenceBranch” will NOT change what is shown in the User Interface? How can I be certain that the reference branch is actually using the parameter to base the findings off of? What I am trying to figure out is how can we resolve issues in a feature branch, merge that feature branch and propagate the resolved issues into the target branch. For our setup we have Master Branch → Development Branch → Feature Branches. I was trying to setup Development to have a reference branch of Master and each feature branch to have a reference branch of Development. I was hoping that setting the “-Dsonar.newCode.referenceBranch=development” would allow me to achieve this behavior without having to go into the User Interface. Master and Development are long live branches which I can manually set up the new code reference branch in the User Interface, but it becomes a hassle if I have to set the reference branch manually for every feature branch.

Hi,

When you use analysis parameters to set something that’s also settable via the UI, what you’re doing is overriding the UI default for that analysis. Those one-off settings are just that: one-off. They never overwrite what’s been set through the UI.

Given your setup, it seems that your best option is to use the UI (or the API, if the UI really gives you hives :joy:) to set up main and develop granularly, and then configure the project-level setting to point to develop.

 
HTH,
Ann