SonarQube New Code Issue Discovery


I’m using SonarQube Enterprise v8.7 and I have two questions to ask.

One: Is there a feature in SonarQube to fail a scan or analysis when new issues are found in the code?

In this case, I’m running my analysis via a Jenkins job and I would like to implement a solution whereby the job fails if new issues are discovered in the code.

Two: Considering that measures on new code will only show up after the branch has been analyzed a second time, is it possible to have a baseline branch against which every new branch is analyzed?

This way when a new branch is analyzed for the first time, its analysis is compared against this baseline/default branch and we can get measures on new code on the first run or scan.

Thank you


First, your version is past EOL. You should upgrade at your earliest convenience. Your upgrade path is:

8.7 → 8.9.1 → 9.0 (last step optional)

Regarding your questions, generally it’s best to keep it to one topic per thread. These are related, so I’ll try to address both, but if there are followups, I reserve the right to pick which fork to follow and ignore the other. :grin:

First, you want to set your Quality Gate up to fail for Issues on New Code. I don’t like to think that you would fail it for any issues (surely a new TODO comment shouldn’t cause a pipeline failure?) so I’ll just point out that you have multiple metrics at your disposal to make this work. And specifically, I’d really recommend you focus on ratings, so Reliability Rating on New Code, Security Rating on New Code & Maintainability Rating on New Code.

Once you’ve configured your QG, you’ll need to set up the pipeline failure. That’s well documented and I’ll go ahead & ask you to open a new thread if you have specific questions about it.

In fact, it sounds like you’re either looking for PR analysis or the “Reference Branch” setting for the New Code Period. I guess you want to set the project-level New Code Period to use the main branch as the reference branch - newly created branches will get that setting by default - and then set the main branch separately.


1 Like

Thanks a lot, Ann for your very clear explanation.

I’m just going to look for documentation on the upgrade process and then start mine.


1 Like

Hi @ganncamp

I have attempted to implement this solution and I have two follow-up questions as a result, please.

With regards to setting the New Code Period at the project level
Must it be the Main Branch that is used as the baseline or can any other branch that has been previously analyzed be used?

Also, when you say that newly created branches will get that setting by default, what happens to already existing branches that have already been scanned once before the change was made? What setting will they inherit on their second scan?

In my case, I have set the New Code Period and used an already existing branch Not Main as the Reference Branch. But when other already existing branches are scanned, nothing appears under New Code.

I’m not sure if I’m missing something.


Not at all. I just made an assumption.

Very good question. It depends on what their setting is now. If it’s “Project setting”, like so:

Then they’ll get the new project setting. But if they’ve been explicitly set to something else, they’ll retain that.

To be honest, I’ve never made time to play around with this setting. However, I believe there’s an element of chronology here. When was your Not Main created relative to the other branches in question?


1 Like


You’re a star and a genius…

Thank you so much. You’ve just saved me pulling out what’s left of my hair.

1 Like