0
votes

I have configured Jenkins job as below for SonarQube analysis.

My Job was successful and I received a email for the same.But When I see the SonarQube site I see that Quality Gate failed.How to set the parameters under my Jenkins job so that my email triggered should be Failed.

2

2 Answers

1
votes

This is a question of apples and oranges. Or let's say cranberries and oranges, since some people do combine the two, and that's what you're after.

For the record, doing this is a bad idea. Why? If the Jenkins build fails, is that because the code didn't compile, (didn't check out, didn't... whatever) or because the quality gate failed?

Assuming the point is to be notified of a quality gate failure, you'd be better off using SonarQube's native "New quality gate status" notifications.

But okay. To accomplish what you're after: use the Build Breaker plugin. It will suspend the Jenkins job until analysis report processing is complete on the server side (which could take an indeterminate time, depending on your server load), and return a -1 if the project failed its Quality Gate.

0
votes

You can use the Jenkins built-in step waitForQualityGate as described in SonarQube documentation. For example, in a scripted Pipeline you can decide what to do based on the QualityGate result like this:

def qg = waitForQualityGate()
if (qg.status == 'OK') {
   [...]
}