This bash script waits for the sonar's quality gates and breaks the build when any quality gate fails.
This bash script was created to be used in Azure DevOps because there is no way to break builds when quality gates fail unless it's with gradle or maven plugin. So, this bash script supplies it, you can break any build when quality gates fail because it is agnostic to any lenguage or build tool.
- YAML
# Before execute the sonar analysis in previous steps
steps:
- script: /pathWhereShIs/quality-gates-checker.sh $(SonarToken) $(SonarServerName) /pathWhereDoscannerworkIs/.scannerwork/report-task.txt
displayName: Wait for sonar analysis- GUI designer
It was tested in jenkins to check the rigth operation in a CI server different to Azure Devops.
- Jenkinsfile
# Before execute the sonar analysis in previous stages
stage('Qulity - gates - test') {
steps {
sh '/pathWhereShIs/quality-gates-checker.sh ${SonarToken} ${SonarServerName} /pathrWhereDoscannerworkIs/.scannerwork/report-task.txt'
}
}The bash script needs 3 parameters to be executed correctly:
./quality-gates-checker.sh $(SonarToken) $(SonarServerName) $(reportTask)-
$(SonarToken) Sonar token to auth in sonar server API
-
$(SonarServerName) Sonar server name used for the analysis
-
$(reportTask) File create by sonar-scanner at moment of analysis; normally is .scannerwork/report-task.txt and its location is in the project root
Execution example:
./quality-gates-checker.sh my_token_here sonarcloud.io /home/carlosdeveloper10/aws_face_auth/.scannerwork/report-task.txt- When quality gates fail on Azure DevOps
- When quality gates pass on Azure DevOps
- jenkins




