Search code examples
sonarqubesonarqube5.1

Configure SonarQube Quality Gate threshold for new issues rather than increase in value


I'm using SonarQube 5.1.2.

I would like to configure a Quality Gate for SonarQube projects.
However, because these are legacy projects, according to existing rules, we have already some blocker and critical issues

I would like to define a Quality Gate based on the new issues that will appear from now on, and promote a continuous decrease on those issues while not allowing new blocker issues to be introduced.

For instance, I could use the criteria "New Blocker Issues" since a given date, but won't work exactly as I would like, because if someone adds a blocker issue, but while that, someone resolves an existing blocker issue, the balance will be null, and thus the quality gate won't change to 'red'.

In another hand, if I configure the threshold "Blocker issues", value > 0, since last analysis, won't work also, because the next time SonarQube runs, if no new blocker issues are introduced, the quality gate will change to 'green' even the new blocker issue in previous analysis was not fixed at all.

Instead, I was expecting that SonarQube was able to actually detect "new issues" (not the difference in the amount of them), and keep counting them as "new" because we want to enforce that no new "Blocker issues" are introduced for that period, while existing issues are resolved.

Is there a way to configure the Quality Gate to reflect this?
Maybe I'm simply configuring it in the wrong way. I found 2 criteria: "Blocker issues" and "New blocker issues" but they seem to behave exactly the same when combined with a period.


Solution

  • SonarQube is designed to address your use-case i.e. focus on New Code. It's the point of its Water Leak Paradigm.

    In short: when your Quality Gate has a condition that says "No New Issue over the Leak Period", SonarQube will make sure there there is "No New Issues created after the beginning of the Leak Period" i.e. "Only issues that were there before the Leak Period are tolerated" i.e. "I tolerate legacy issues, I strictly do not tolerate any new issue" i.e. "I do not leak New Issues".

    Back to your query:

    For instance, I could use the criteria "New Blocker Issues" since a given date, but won't work exactly as I would like, because if someone adds a blocker issue, but while that, someone resolves an existing blocker issue, the balance will be null, and thus the quality gate won't change to 'red'.

    Nope, SonarQube won't care about the balance. SonarQube will look for Issues that were created after that date (more generally: after the beginning of the Leak Period). You'll be able to visualise that on the Project Homepage (example), and the Quality Gate will break if it's configured accordingly (e.g. No New Blocker Issues).

    Give it a try with sample code where you remove an existing issue and add a new one (don't just move an existing issue to a different line as SonarQube has Issue Tracking mechanisms).

    P.S.: 5.1.2 is pretty old, you should upgrade to the latest SonarQube LTS (5.6.x as of this writing). Leak Period is even more present in the UI/UX, and related Quality Gate configuration is more comprehensive.