Define Quality Gate with bug percentage?

When analyzing my code I have a couple of Bugs. I would like to define a Quality Gate for a valid percentage bugs/LOC, how do I do that?
Let’s say I have 100 bugs and 20.000 LOC, that would be 0.5% bugs. Now if I want to specify that more that 0.5% bugs should give status Failed, is that possible?

When configuring metrics for Quality Gate I can add “Bugs” and select “less than” … but that seams to be an absolute number. That’s not usable since 100 bugs might be OK if I have 1.000.000 LOC.

I have SonarQube 6.7.5.


This is not possible.

A Quality Gate is meant to answer a single question: can I deliver my project to production today or not? A ratio of bugs to lines of code doesn’t really help you determine that (the goal should be no new bugs, regardless of how large your application is).

I would recommend reading up on the Fixing the Water Leak metaphor and focus your Quality Gate conditions on preventing bugs in New Code (the “Leak Period”), rather than focusing on a ratio if bugs / lines of code.


OK, sounds reasonable. Thanks for input!