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:
ceTaskUrland examine the "status" value:
You can get the
ceTaskURL from <work_dir>/report-task.txt, which is generated at the end of the analysis.
projectKey=test:fake-project-for-tests serverUrl=http://localhost:9000 dashboardUrl=http://localhost:9000/dashboard/index/test:fake-project-for-tests ceTaskId=AVF8MXobVNmO-QF545eY ceTaskUrl=http://localhost:9000/api/ce/task?id=AVF8MXobVNmO-QF545eY
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
analysisIdfrom the JSON returned by
api/qualitygates/project_status?analysisId=YYYto check the status of the quality gate