# Sonar Quality Gate behavior in Jenkins pipeline is unstable

**URL:** <https://community.sonarsource.com/t/sonar-quality-gate-behavior-in-jenkins-pipeline-is-unstable/18020>\
**Category:** SonarQube Server / Community Build\
**Tags:** jenkins, sonarqube\
**Created:** [December 20, 2019, 5:42pm UTC](https://community.sonarsource.com/t/sonar-quality-gate-behavior-in-jenkins-pipeline-is-unstable/18020 "2019-12-20T17:42:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![arielman](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/arielman/32/8135_2.png) [@arielman](https://community.sonarsource.com/u/arielman)\
**Post date:** [December 20, 2019, 5:42pm UTC](https://community.sonarsource.com/t/sonar-quality-gate-behavior-in-jenkins-pipeline-is-unstable/18020/1 "2019-12-20T17:42:08Z")

</div>

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

```auto
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:

```auto
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?

---

<div class="post-metadata">

**Author:** ![anon67236913](https://avatars.discourse-cdn.com/v4/letter/a/c37758/32.png) [@anon67236913](https://community.sonarsource.com/u/anon67236913)\
**Post date:** [December 20, 2019, 7:11pm UTC](https://community.sonarsource.com/t/sonar-quality-gate-behavior-in-jenkins-pipeline-is-unstable/18020/2 "2019-12-20T19:11:59Z")

</div>

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](https://jira.sonarsource.com/browse/SONARJNKNS-316) 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.

> [@arielman](#):
>
> 13:59:47 Checking status of SonarQube task ‘XXXXXXXXXX’ on server ‘Sonar’ 13:59:47 SonarQube task ‘XXXXXXXXXXXX’ status is ‘SUCCESS’

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

> [@arielman](#):
>
> 12:22:10 SonarQube task ‘XXXXXXXXXX’ status is ‘PENDING’

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

---

<div class="post-metadata">

**Author:** ![arielman](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/arielman/32/8135_2.png) [@arielman](https://community.sonarsource.com/u/arielman)\
**Post date:** [December 20, 2019, 7:38pm UTC](https://community.sonarsource.com/t/sonar-quality-gate-behavior-in-jenkins-pipeline-is-unstable/18020/3 "2019-12-20T19:38:28Z")

</div>

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](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:

```auto
    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}"
                    }
        }
    }

```

---

<div class="post-metadata">

**Author:** ![arielman](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/arielman/32/8135_2.png) [@arielman](https://community.sonarsource.com/u/arielman)\
**Post date:** [December 23, 2019, 8:04am UTC](https://community.sonarsource.com/t/sonar-quality-gate-behavior-in-jenkins-pipeline-is-unstable/18020/4 "2019-12-23T08:04:14Z")

</div>

@anon67236913 can you comment on it?

---

<div class="post-metadata">

**Author:** ![anon67236913](https://avatars.discourse-cdn.com/v4/letter/a/c37758/32.png) [@anon67236913](https://community.sonarsource.com/u/anon67236913)\
**Post date:** [December 23, 2019, 11:11am UTC](https://community.sonarsource.com/t/sonar-quality-gate-behavior-in-jenkins-pipeline-is-unstable/18020/5 "2019-12-23T11:11:30Z")

</div>

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
