I have a gitlab-ci integration that require a sonar analysis and if the quality gates pass, to build a docker image.
Is this possible using gitlab-ci ?
I have a gitlab-ci integration that require a sonar analysis and if the quality gates pass, to build a docker image.
Is this possible using gitlab-ci ?
Thanks Sahit for the answer. It seems the solution is for Linux. I wanted it to be Windows compatible.
Refer the link for more information https://www.codeproject.com/Tips/5165909/Gated-Check-in-in-Git-repository
To break the CI build for a failed Quality Gate,
1.Search in /report-task.txt the values of the CE Task URL (ceTaskUrl) and CE Task Id (ceTaskId)
2.Call /api/ce/task?id=XXX where XXX is the CE Task Id retrieved from step 1 Ex:- https:///api/ce/task?id=Your ceTaskId
3.Wait for sometime until the status is SUCCESS, CANCELED or FAILED from Step 2
4.If it is FAILED, break the build (Here failure is unable to generate sonar report)
5.If successful,then Use the analysisId from the JSON returned by /api/ce/task? id=XXX(step2)and Immediately call /api/qualitygates/project_status?analysisId=YYY to check the status of the quality gate. Ex:- https:///api/qualitygates/project_status?analysisId=Your analysisId
6.Step 5 gives the status of the critical, major and minor error threshold limit
7.Based on the limit break the build.
8. Follow proper indentation while using the script
You should try the Sonar Build Breaker plugin. It enables returning non-zero which would break the Gitlab CI Runner's build, not performing the next step (building the Docker image).
Create a .gitlab-ci.yml file in the root of your project:
A commit to Gitlab will run the
sonarqube
stage and continue withdocker_build
only if sonarqube passes the Quality Gate.