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.
- $url = (findstr "ceTaskUrl" "").Substring(10)
- sleep 10 #Need some buffer time to get the report updated from sonarqube analyzer
- $response = &"" -u : $url #using curl to login to sonarqube to check analysis ran properly or not. Using sonar admin credentials/token
- $sonardata = $response | ConvertFrom-Json #converting returned data to json
- $sonarBuildStatus=$sonardata.task.status
- |
if ("$sonarBuildStatus" -eq "SUCCESS"){
echo "SONARQUBE ANALYSIS IS SUCCESSFUL"
$sonarAnalysisId= $sonardata.task.analysisId
$projurl = (findstr "serverUrl" "").Substring(10)
$projNewUrl = $projurl+"/api/qualitygates/project_status?analysisId="+$sonarAnalysisId
$projresponse = &"" -u : $projNewUrl
$sonarprojdata = $projresponse | ConvertFrom-Json
$sonarProjStatus=$sonarprojdata.projectStatus.status
if ("$sonarProjStatus" -eq "ERROR"){ #Checks if the project has meet all the quality gates specified
echo "SONARQUBE QUALITY GATES FAILED FOR $CI_PROJECT_NAME"
echo $sonarprojdata.projectStatus.conditions
exit 1 #breaks the build for violations
}
else{
echo "SONARQUBE QUALITY GATES SUCCESSFUL FOR $CI_PROJECT_NAME"
echo $sonarprojdata.projectStatus.conditions
exit 0
}
}
else{
echo "SONARQUBE ANALYSIS FAILED"
exit 1 #breaks the build for violations
}
Refer the link for more information https://www.codeproject.com/Tips/5165909/Gated-Check-in-in-Git-repository