Using reference branch parameter in pipelines sonar.newCode.referenceBranch

Hello,

  • which versions are you using - Sonarqube Enterprise edition 9.4

Is referencing a branch from SonarQube UI available globally ? I know we have a parameter sonar.newCode.referenceBranch that can be used in our pipelines to override default project settings, in our organization we want to have main branch as the reference branch for all the projects but there are few projects that use master or develop as their main branch. is there a parameter that can be added in the sonar.project.properties file that would consider the projects main branch as the reference branch instead of having to specify the branch name(master/develop) ?

Thank you

Hey there.

There’s no global setting that exists to set a specific reference branch as the default, but at a project-level you can set the reference branch to, by default, by a specific branch (in the project-level Administration > New Code)

This ensures the reference branch for any new branches of a project is the target branch. No sonar-project.properties setting needed.

Thank you for your response.
I want to have this same setting for 400+ projects, it is not feasible to do it manually. Is there a way to automate this ?

Using the POST api/new_code_periods/set Web API should help you. You can find a link to the Web API documentation for your SonarQube instance in the footer of your instance, and you might also find this guide helpful:

I’d also invite you to raise a thread in our “Product Manager for a Day” category, or I can just move this thread there if you’d like.

Hi Colin,

Thank you !! Yes please move this thread to Product manager for a day category.

Thanks