Sonarqube api qualitygates/project_status recieve wrong status

Hi all,
sonarqube version = 7.9 LTS

We use API qualitygates/project_status to grep status of quality gates and send email notiffication if quality gates --> if (qgate != ‘OK’)
but the API i thinks checking the previous analysis so it’s parsing false status
for examples
11:32 AM Version: 1.0
11:31 AM Quality Gate: Green (was Red)

we just run analysis on 11:32 but the history has two analysis and the api result give wrong status (not OK) but if i browse the analysis it’s show the quality gates is passes

Are you waiting for that last analysis to be processed?
It might take several minutes for the quality gate to be updated after the scanner runs.
At the time you see the quality gate green in dashboard, project_status should also be returning it green (that’s how the dashboard gets the information!)

Hi Duarte,

i just run the sonar analysis and the checking quality gate in same stage pipeline on the jenkins,
the groovy script is something like below:

stage (“Run Sonar Scanner And Result Notification”){
sh “docker run -i --rm -w /workdir -v pwd:/workdir sonar-runner:latest”

//Quality Gates

    def baseurl = "https://sonarqube”
    def sonarurl = baseurl.replaceAll("\\r\\n|\\r|\\n", "")
    def key = xxx
    def cutkey = key.replaceAll("\\r\\n|\\r|\\n", "")
    def json = sh(script:"curl -k -u ${password} ${sonarurl}/api/qualitygates/project_status?projectKey=${cutkey}", returnStdout:true)
    def obj = new groovy.json.JsonSlurperClassic().parseText(json)
    def qgate = obj.projectStatus.status
    if (qgate != 'OK') {
     echo "sending email..........................................."


how can i add waiting until the analysis is finished?

Hi Duarte,

If i check further the false api status is send if there’s a change from red - green,
so previous scan result is red then we do mitigation then run analysis again and the status now is pass but the api result still send the red status.

The scanner writes in a file report-task.txt that is in the scanners Working Directory and contains a URL to get the background task status. For example, ceTaskUrl=http://{server-url}/api/ce/task?id=AXIPoFlQOQOkc-vr_dd5. Your script should use this to check if the background task finished before checking the project’s quality gate.

Hi Duerte,

I added the script to check the background job and rerun the test but it’s still parsing the wrong status,
after i check further , the sonarqube create two different project analysis (althougt the project key was same,i wonder why sonarqube create two project analysis although the project key was same (maybe because there’re different branch?

Maybe you’re using the deprecated sonar.branch in your scanner? Do you have the developer edition?

Hi Duarte,

I’m using community edition. and i don’t user sonar.branch in the

Just to clarify, when you say that SonarQube creates two different project analysis, do you mean you have 2 different projects showing up in SonarQube? If that’s the case, there’s no way they have the same key.

Hi Duarte,

Thanks for tour help,
after checking there’s two project keys as you said, sorry my bad.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.