Projects with 2 sonar analysis reports wrong quality gate status

  • SQ version: 7.3
  • Jenkins Sonar scanner: 2.8.1

I’m analyzing a .Net project in SonarQube from Jenkins.
The project has a backend and a frontend whose build and analysis is run in 2 parallel stages in Jenkins, publishing the results in 2 separated SQ projects.
Now i’m trying to get the result of the quality gate for each project, to update the status of the Jenkins build accordingly.
But the result i get from waitForQualityGate is incorrect for the second analysis.
Frontend analysis completes first with a warning status, waitForQualityGate returns warn status, ok.
Backend analysis completes second with a failure status, waitForQualityGate returns warn status, ko.

I think the issue comes from “SonarQube taskId is correctly attached to the pipeline context”, as described in https://docs.sonarqube.org/latest/analysis/scan/sonarscanner-for-jenkins/#header-6
My guess is that the taskId of the frontend analysis is also used for the backend. I did not find a way to manage this waitForQualityGate does not accept any parameter.

I tried posting backend and frontend analysis to the same SQ project to avoid mixing results, but in this case, SQ switches continuously between backend and frontend profiles, only keeping the results of the last analysis (backend in my case).

How should i address this issue?

Hi @emex

I think the issue come from the parallel execution. withSonarQubeEnv will ends by looking in the workspace for the file report-task.txt, and attach to the Jenkins build some metadata (including the task id). waitForQualityGate will then retrieve this metadata from the Jenkins build and look for QG status.

If you run multiple analyses in sequence, it should work fine:

withSonarQubeEnv {
  // run analysis of project A with scanner
} // look for report-task.txt, and store taskid A in build metatata
waitForQualityGate // use taskid A

// Here you may have to remove report-task.txt from the first build from the workspace

withSonarQubeEnv {
  // run analysis of project B with scanner
} // look for report-task.txt, and store taskid B in build metatata
waitForQualityGate // use taskid B

If you run both in parallel, there is no guarantee that the taskId picked by waitForQualityGate will be the correct one.

So let say that’s a limitation of our current design: don’t run multiple analysis in parallel.

Thanks Julien, it’s working fine after running SQ analysis sequentially in the Jenkins pipeline.