Sonarqube scan using gradle fails in the "Quality Gate" step of jenkins pipeline

I want to find an alternative way for sonar build-breaker plugin and found this article

I followed the steps mentioned and configured the pipeline as

node {
  stage('SCM') {
    git 'https://github.com/SonarSource/sonar-scanning-examples.git'
  }
  
  stage('build & SonarQube Scan') {
    withSonarQubeEnv('sonarhost') {
       dir("${env.WORKSPACE}/sonarqube-scanner-gradle/gradle-basic"){
      sh "pwd"
      sh 'dir $WORKSPACE/sonarqube-scanner-gradle/gradle-basic'
      sh 'echo ${PWD}'
      sh 'gradle tasks --all'
      sh 'cd $WORKSPACE/sonarqube-scanner-gradle/gradle-basic'
      sh 'echo ${PWD}'
      sh 'gradle sonarqube --debug -Dsonar.login=my-login-token'
    } // SonarQube taskId is automatically attached to the pipeline context
  }
}
 
// No need to occupy a node
stage("Quality Gate") {
  timeout(time: 1, unit: 'HOURS') {
    def qg = waitForQualityGate(webhookSecretId: 'my-login-token') 
    if (qg.status != 'OK') {
      error "Pipeline aborted due to quality gate failure: ${qg.status}"
    }
  }
}
}

The pipeline goes upto timeout(time: 1, unit: ‘HOURS’) step and then it fails with the error

Checking status of SonarQube task 'AX_5A5YSuhDrgrHn3OgE' on server 'sonarhost'
org.sonarqube.ws.client.HttpException: Error 404 on http://sonarqube-domain.com:9000/api/ce/task?id=AX_5A5YSuhDrgrHn3OgE : 
	at org.sonarqube.ws.client.BaseResponse.failIfNotSuccessful(BaseResponse.java:36)
	at hudson.plugins.sonar.client.HttpClient.getHttp(HttpClient.java:38)
	at hudson.plugins.sonar.client.WsClient.getCETask(WsClient.java:51)
	at org.sonarsource.scanner.jenkins.pipeline.WaitForQualityGateStep$Execution.checkTaskCompleted(WaitForQualityGateStep.java:238)

And when i checked the earlier log output, i saw this

Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
09:17:16.205 [INFO] [org.sonarqube.gradle.SonarQubeTask] More about the report processing at http://sonarqube-domain.com:9000/sonar/api/ce/task?id=AX_5A5YSuhDrgrHn3OgE

The link where the report is uploaded and the link at the quality gate step are different
Error 404 on http://sonarqube-domain.com:9000/api/ce/task?id=AX_5A5YSuhDrgrHn3OgE and
More about the report processing at [http://sonarqube-domain.com:9000/sonar/api/ce/task?id=AX_5A5YSuhDrgrHn3OgE](http://sonarqube-domain.com:9000/sonar/api/ce/task?id=AX_5A5YSuhDrgrHn3OgE)

From where is this link picked up?
How can i fix this.

i tried to fix it by adding sonarqube link as sonar-host:9000/sonar in jenkins global settings page and now the error is something else.

SonarQube task 'AX_5Mge_uhDrgrHn3OgG' status is 'PENDING'

A webhook secret id was configured, but the corresponding credential could not be found
ERROR: Pipeline aborted due to failed webhook verification

Answering my own question “adding sleep 20” in between steps solved the error.
Thanks for reading and hope this helps someone else

1 Like

Hi,

since Sonarqube 8.9 there is a new way, if for whatever reasons the waitForQualityGate step doesn’t work.
You might use the property sonar.qualitygate.wait=true which works the other way around,
means it does an active polling for the quality gate result instead of creating a listener and waiting for the webhook.
There’s also sonar.qualitygate.timeout with a default of 300 sec.

see

https://docs.sonarqube.org/latest/analysis/ci-integration-overview/#header-1

Gilbert