How to handle inprogress status for Sonarqube Quality gate

You might have setup CI CD pipeline with jenkins and sonarqube for code analysis and quality gate and noticed that it works well for sometime and then suddenly in one of the successive builds, the pipeline starts getting stuck in the quality gate process with in-progress status. It gets stuck as the status required by jenkins is either PASS or FAIL. What we typically do to come out of this in-progress state is either wait for the timeout to occur or abort the stage manually.

Following is the basic code for quality gate configuration which was used in jenkins when the in-progress issue had occured : stage(“Quality Gate”){

        timeout(time: 10, unit: ‘MINUTES’) {
              def qg= waitForQualityGate()
            if (qg.status!= ‘OK’){
                error “Pipeline aborted due to quality gate failure: ${qg.status}”
              echo ‘Quality Gate Passed’


Below are the logs that were generating for the quality gate stageon running the job.

[Pipeline] stage[Pipeline] { (Quality Gate) [Pipeline] timeout Timeout set to expire in 10 min [Pipeline] { [Pipeline] waitForQualityGate Checking status of SonarQube task ‘AW0-VlEAbdFtWVenh2fm’ on server ‘SonarQube_Home’ SonarQube task ‘AW0-VlEAbdFtWVenh2fm’ status is ‘IN_PROGRESS’ Aborted by unknown [Pipeline] } [Pipeline] // timeout [Pipeline] } [Pipeline] // stage [Pipeline] step  


What is happening here is that the quality gate is unable to read the result of Sonarqube analysis. The following step in the code:

    def qg= waitForQualityGate()

will print “IN PROGRESS” unless the waiting time expires or the operation is aborted manually.  This problem usually occurs on slow machines.  Jenkins checks the result from Sonarqube while Sonarqube is still processing the result. This usually happens just few seconds (at times minutes) before the result of sonarqube analysis is available to quality gate. If the thread is set to sleep [sleep(<time in seconds>)]  for 1-3 minutes (as per system performance), which means that Jenkins will be able to check the result from Sonarqube after this delay, it will be able to read the sonarqube analysis result.

e.g. Adding below as the last step in the “Quality gate” stage will seem to temporarily resolve the problem:
sleep(n), where n is the duration in seconds.

However, setting sleep time is not a permanent solution to the problem.


 The solution that worked for me was quite straight forward. It was more like a step that was missed while designing the pipeline. The solution is to create a webhook from sonarqube server and point it to the jenkins. This can be found out under  Menu Administration->Configurations->Webhooks as shown in below screenshot. Provide the url as http://jenkins-server-url/sonarqube-webhook.

The waitForQualityGate step polls only once (for various reasons) and then pause the pipeline in the infamous in-progess status, waiting for a webhook to be received.  If the webhook never fires (isn’t configured correctly/ or cannot communicate/plugin bug) from sonar to jenkins, the call stays stuck and hung until the timeout is hit or is aborted manually.

This is how the Jenkins will process the stage post webhook implementation:

  • First it will check whether the quality gate check is already complete. It will immediately return if it is.
  • If not it then it will wait until sonarqube completes the processing and sends the webhook call to jenkins server. (This is also why setting the thread to sleep seems to work because sonarqube completes its analysis within that interval.).

Let us know if you found this post useful.   

Leave a Reply

Your email address will not be published. Required fields are marked *