New Code configuration for a group of branches (regex)

Hello, I’d like to ask the community about this specific matter, hopefully someone can point me in the right direction. Here are the details:


SonarQube: Enterprise Edition - Version 9.9
Scanner: SonarScanner 4.8.0
Java 11.0.14 Alpine (64-bit)
Linux 4.19.0-18-cloud-amd64 amd64
SonarQube is running as a Docker container inside an AWS EC2 server.

Details about the topic itself:

I have a project in SonarQube that has its own New Code configuration: there is a “development” branch, which is the main branch, and the other branches are compared to it when analyzed (Project setting → Define a specific setting for this project → Reference branch → Choose a branch: development). The “development” branch has its own definition of New Code (it references the “master” branch). So, the “flow” is: feature branches → development → master.

But I have a specific group of branches for releases (e.g. release-2023.1, release-2023.2, etc.). These branches are created from “development” and merged later to “master”. So, they should have the New Code definition just like the “development” branch i.e. Reference branch “master”). What happens is that every time I create a new release branch, I have to run the first scan, then go to the SonarQube UI, manually edit the New Code definition for it (“Set a specific setting for a branch”), to point to “master”, and then run the scan again.

To avoid that, it would be great to have a way to configure what New Code means for a group of branches, where I could use a regular expression, for example “release-.*” and it would automatically cover any branch I create with this pattern.

Is there a workaround to achieve that? Or would that be a new feature that would need to be developed from scratch?

Thank you!

1 Like

Hello Daniel Lacher,

Thank you for your feedback.
Currently, what you can do is to use web API to set desired reference branch (master in this case) as the new code definition for release branches.

POST api/new_code_periods/set

You will need ‘Administer’ rights on the specified project to change the project setting.

Thank you, @vivek.reghunath , I’ll try that and let you know.

Hello @vivek.reghunath ,

I’ve tested the web API and it works fine. I can use my Jenkins pipeline to trigger the API call on the fly. Thank you for that, I’ll mark your answer as the solution.

If possible, though, it would be nice if the SQ Team could add a new feature, to make possible the use of regular expressions to define New Code. Thanks.

1 Like

Glad to know that it worked for you.
We took note of the need and will continue to monitor interest for new code definition with regular expression on our side.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.