Quality Gate condition to check number of issues decreased

q_gate
fix_the_leak

(Roberto Silva) #1

Hello,

I’m looking for help setting up quality gates which will promote fixing issues.
Using SonarQube 6.7 atm.

The project is in a bad state (215 total issues) and I’d like to fail the QG anytime a new analysis is run and the total number of issues hasn’t decreased.

When adding conditions to QG I don’t see any type of variables I can use to reference the number of issues, is this possible? It seems to always expect a fixed number.

For new issues I am assuming I can just use the ‘New Issues’ condition and set error to 1?

Thanks


(Nicolas Bontoux) #2

Best and simplest approach there would be to leverage the default (and recommended) Quality Gate conditions: https://next.sonarqube.com/sonarqube/quality_gates/show/30 (i.e. making sure that ratings on new code are pristine).

With respect to your ‘must-decrease’ policy:

I’d like to fail the QG anytime a new analysis is run and the total number of issues hasn’t decreased.

That’s a bit harsh, and is not doable with Quality Gate conditions out-of-the-box. I recommend you read about the recommended methodology: Fixing the Water Leak . And take the time to think about the perverse aspect of what you have in mind: I, as a developer, work on this project containing 215 issues, and implement a brand new Java class, independent from all other legacy code. If your policy was in place, then even if my code was ‘impeccable’ (no rule violated), then my changeset would be rejected because I still don’t decrease the number of overall issues. I lose confidence/sympathy towards this tool, and will find ways to cheat around it (or quickly get my change validated by fixing one of 215 issues without thinking much of it) :frowning_face:


(Roberto Silva) #3

Great article, thanks for your suggestion!

I did not realize the default conditions were applied to new code, mostly because the Quality Gate always fails.
Any idea why does that happen? The reliability and security rating conditions on new code never pass if set to A even when making minor changes.
Edit: Just realized this happening due to the leak period.