See https://docs.sonarqube.org/display/SONAR/Documentation for current functionality
Organizations that want to see their Quality Gates results reflected in the success/failure of their build jobs can use the Quality Gates Web Service to break the build when the project fails the gate. In previous versions of the SonarQube Server, this functionality was available via a plugin.
The import of your raw results (issues, low-level measures) and the computation of aggregated measures is done on the server side in a "Background Task". So once the scanning of your code is finished on the CI server, the analysis step ends and returns control to the job. At this stage, the aggregate measures needed for Quality Gate compliance aren't yet computed; you have to wait for the SonarQube Server to digest the scan results before proceeding.
To break the CI build for a failed Quality Gate, use WS API calls in a loop to wait until processing is finished, and then check Quality Gate web service:
- call the analysis's
ceTaskUrland examine the "status" value:
- PENDING or IN_PROGRESS - check again later
- FAILED or CANCELED - break the build?
- SUCCESS - move forward
- call Quality Gate web service for status
You can get the
ceTaskURL from <work_dir>/report-task.txt, which is generated at the end of the analysis.
Workflow of WS API Calls
- Search in <work_dir>/report-task.txt the values of the CE Task URL (
ceTaskUrl) and CE Task Id (
/api/ce/task?id=XXXwhere XXX is the CE Task Id retrieved from <work_dir>/report-task.txt (save it as
- Do the Step 2 until the status is SUCCESS, CANCELED or FAILED
- If the status is FAILED => break the build
- If the status is SUCCESS
- Use the
analysisIdfrom the JSON returned by
- Immediately call /
api/qualitygates/project_status?analysisId=YYYto check the status of the quality gate
- Use the