Sonar Quality Gate behavior in Jenkins pipeline is unstable

I have some pipelines in Jenkins, with the SonarQube stage. In some builds it is aborted due to time out:

12:19:01 Sleeping for 3 min 0 sec
[Pipeline] timeout
12:22:10 Timeout set to expire in 25 min
[Pipeline] waitForQualityGate
12:22:10 Checking status of SonarQube task 'XXXXXXXXX' on server 'Sonar'
12:22:10 SonarQube task 'XXXXXXXXXX' status is 'PENDING'
12:47:10 Cancelling nested steps due to timeout

and in some other builds it pass:

13:56:47 Sleeping for 3 min 0 sec
[Pipeline] timeout
13:59:47 Timeout set to expire in 25 min
[Pipeline] {
[Pipeline] waitForQualityGate
13:59:47 Checking status of SonarQube task 'XXXXXXXXXX' on server 'Sonar'
13:59:47 SonarQube task 'XXXXXXXXXXXX' status is 'SUCCESS'
13:59:47 SonarQube task 'XXXXXXXXXXXX' completed. Quality gate is 'WARN'

what might be the reason for it? how can I keep it stable?

Hi,

assuming you’re using some recent versions of Sonarqube, Sonarqube scanner for Jenkins,
this details are missing.
Do you use the Sonarqube stages within parallel { .. } ?
We’ve noticed some glitches in that area and there’s already one ticket to tackle some of the problems.

From my experience you don’t need use sleep if all is configured properly.
The communication has to work in both ways Jenkins <-> Sonarqube.

Workflow:
After analysis is finished, the report archive is uploaded to Sonarqube server, you should see the
analysis id on the administration / background tasks page.

waitForQualityGate() does an initial call to Sonarqube server to see if the background is already
done - if yes, there’s no need to wait for webhook anymore.
That’s what you see in your second example, checking status and status is success right afterwards.

As this works, the Jenkins > Sonarqube part is fine, you should also see in Sonarqube access.log,
search for the analysisid.

If the background task takes longer, Sonarqube scanner for Jenkins will print

then it waits for webhook until timeout.
So in your case the problem is the Sonarqube > Jenkins part.
On the administration/configuration/webhook page you will see that webhook delivery has failed
with ‘Server unreachable’.
Using sleep increases the chances to camouflage the webhook problem, as the initial call is delayed
and the background task might be finished meanwhile.

TL;DR
Check the Sonarqube > Jenkins part of configuration.
Seems the webhook delivery doesn’t work as Jenkins is not reachable for Sonarqube.

Gilbert

so what you’re actually saying, that my webhook is not really working? what’s wrong with below configuration:
name: jenkins_care
URL: http://XXXXX:YYYY/sonarqube-webhook/

Adding some more details:
Version: 6.7.1 (build 35068)
I’m not using Sonarqube stages within parallel { … }
Trigger command in bitbucket file:

    stage('Sonar Quality Gate') {
        sleep 180
        timeout(time: 25, unit: 'MINUTES') {
            def qg = waitForQualityGate()
                    if (!(qg.status == 'OK' || qg.status == 'WARN')) {
                        error "Pipeline aborted due to quality gate failure: ${qg.status}"
                    }
        }
    }

@Rebse can you comment on it?

Hi,

yes, it seems the webhook delivery doesn’t work.
Did you check the webhook deliveries under /admin/webhooks ?
Do you have a Jenkins log for Sonarqube, should be configured like that, all with priority ‘ALL’ ?
hudson.plugin.sonar
hudson.tools
org.sonarsource
Also your Sonarqube version is rather old, EOL already.
You should update to the latest 7.9.2 LTS or 8.1.

Gilbert