Waitforqualitygate is not working even sleep added

Hi everyone!

Specifications (all in Jenkins is up to date with latest)
Jenkins version: 2.190.3
Sonar Quality Gates Plugin: 1.3.1
SonarQube Scanner for Jenkins: 2.10

What I’m trying to achieve is get a build in a determinate state (OK/FAIL) depending in SonarQube execution.
To test this,

  • SonarQube Quality Gates reduced to get a “Passed”
  • WebHook created in SonarQube as mentioned in SonarQube page (is showing last delivery when I execute Jenkins job, so is working properly)
  • Created Jenkinsfile stage for Sonar and Quality Gate
  • Added sleep because my feeling is timeout is not working.

Problem:
When I execute the build with Sonar and Quality Gate, always fails, seems is not waiting for SonarQube WebHook response, or is not getting it properly.

JenkinsFile.groovy:

node {

deleteDir();
checkout scm;

try {
    stage('Build') {
        dir("myDir") {
            sh './gradlew build :MyProject'
        }
    }
    stage('SonarQube Scan') {
        withSonarQubeEnv('AWS SonarQube') {
            dir("myDir") {
                sh './gradlew sonarqube'
            }
        }
        sleep(40)
    }
    stage("Quality Gate"){
        timeout(time: 5) { // Just in case something goes wrong, pipeline will be killed after a timeout
            def qg = waitForQualityGate() // Reuse taskId previously collected by withSonarQubeEnv
            if (qg.status != 'OK') {
                error "Pipeline aborted due to quality gate failure: ${qg.status}"
            }
        }
    }
} catch (err) {
    currentBuild.result = 'FAILED'
    notifyFailed()
}

}

Jenkins Output


BUILD SUCCESSFUL in 25s
8 actionable tasks: 1 executed, 7 up-to-date
[Pipeline] }
[Pipeline] // dir
[Pipeline] }
[Pipeline] // withSonarQubeEnv
[Pipeline] sleep
Sleeping for 40 sec
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Quality Gate)
[Pipeline] timeout
Timeout set to expire in 5 min 0 sec
[Pipeline] {
[Pipeline] waitForQualityGate
Checking status of SonarQube task ‘sonarconfiguredtaskid’ on server ‘AWS SonarQube’
[Pipeline] }
[Pipeline] // timeout
[Pipeline] }
[Pipeline] // stage
[Pipeline] emailext
Warning: asd@asd.com is not a recognized user, but sending mail anyway
Sending email to: asd@asd.com
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: FAILURE

Welcome :slight_smile:

assuming you’re using a recent version of Sonarqube as 7.9.1 LTS or 8.0

This plugin is not needed, seems it has been built for an earlier version of Sonarqube - similar
to the Build Breaker plugin.
Uninstall this plugin. Then with proper webhook configuration and communication between
Jenkins <-> Sonarqube it should work.
The waitForQualityGate() method is provided by SonarScanner for Jenkins
Are there any proxies or firewalls involved !?

Gilbert

Hi @Rebse!

Many thanks for the response!

Sonar version is Version 7.9.1 (build 27448).

I tested it again and still not working :confused:

I added in sonar a webhook at project level and also at general level, and is not possible to make it work.

Someone (presumably Jenkins) is requesting for it because it has “Last Delivery” date updated.

|Name|URL|Secret?|Last delivery||
|Jenkins|http://myEc2Machine/sonarqube-webhook/|No|November 28, 2019, 9:03 AM|

I’m for real lost with this, any idea?

Thanks again! :smiley:

@Rebse! It is working!!!

Checking status of SonarQube task ‘AW6xD4nMhUUnInpM’ on server ‘AWS SonarQube’
SonarQube task ‘AW6xD4nMhUUnInpM’ status is ‘SUCCESS’
SonarQube task ‘AW6xD4nMhUUnInpM’ completed. Quality gate is ‘OK’

I’m about to cry, many thanks for your help!

Hi,

glad it works now. What did you do to make it work ?

Gilbert

I found the key in your message

Then with proper webhook configuration and communication between
Jenkins <-> Sonarqube it should work

I checked Sonar authentication and just created another Secret Key, with this, everything was working.

What is required is the sleep(40), if I delete it, the function will not wait for nothing.

If communication between Sonarqube > Jenkins works - think of proxies, firewall and nonProxyHost
settings - no sleep between Sonarqube analysis and waitForQualityGate() should be needed.

Agree, but I don’t have kind of network restriction, not sure why this is not working but well, is a minor issue :stuck_out_tongue: