'Fetch Sonar Quality gate status using api in Azure DevOps pipelines
We have a shell script in submodules which will be called in our Azure pipelines yaml file to fetch the status of the Sonar quality gate using api.
But we are facing issue, its printing the status but along with that some line no error we are getting for if condition.
echo "Fetching the Sonar Quality gate status using api"
quality_gatesstatus=$(curl -u $sonar_token:
https://$sonar_server/api/qualitygates/project_status?projectKey=$SONAR_PROJECT_KEY&pullRequest=$PullRequestId | grep -Po '"status": *\K"[^"]*"')
echo $PullRequestId
echo "Checking the Quality gate status"
if ($quality_gatesstatus != "OK") && ($quality_gatesstatus != "NONE")
then
echo "Check Sonar server and fix the issues"
echo $quality_gatesstatus
exit 1
else
echo "No code violations found"
exit 0
fi
Error logs: Checking the Quality gate status ci/forest/dotnetcore/bin/sonar-quality-gates-checker.sh: line 23: {"projectStatus":{"status":"OK","conditions":[{"status":"OK","metricKey":"new_reliability_rating","comparator":"GT","periodIndex":1,"errorThreshold":"1","actualValue":"1"},{"status":"OK","metricKey":"reliability_rating","comparator":"GT","errorThreshold":"1","actualValue":"1"},{"status":"OK","metricKey":"new_security_rating","comparator":"GT","periodIndex":1,"errorThreshold":"1","actualValue":"1"},{"status":"OK","metricKey":"security_rating","comparator":"GT","errorThreshold":"1","actualValue":"1"},{"status":"OK","metricKey":"new_maintainability_rating","comparator":"GT","periodIndex":1,"errorThreshold":"1","actualValue":"1"},{"status":"OK","metricKey":"sqale_rating","comparator":"GT","errorThreshold":"1","actualValue":"1"},{"status":"OK","metricKey":"new_coverage","comparator":"LT","periodIndex":1,"errorThreshold":"80","actualValue":"100.0"},{"status":"OK","metricKey":"coverage","comparator":"LT","errorThreshold":"80","actualValue":"93.5"},{"status":"OK","metricKey":"new_duplicated_lines_density","comparator":"GT","periodIndex":1,"errorThreshold":"3","actualValue":"0.0"},{"status":"OK","metricKey":"duplicated_lines_density","comparator":"GT","errorThreshold":"3","actualValue":"0.0"},{"status":"OK","metricKey":"new_blocker_violations","comparator":"GT","periodIndex":1,"errorThreshold":"0","actualValue":"0"}],"periods":[{"index":1,"mode":"PREVIOUS_VERSION","date":"2020-09-28T09:09:08+0200"}],"ignoredConditions":false,"period":{"mode":"PREVIOUS_VERSION","date":"2020-09-28T09:09:08+0200"}}}: command not found No code violations found
You can see the status is all OK but still its giving some line number 23 and I feel by default it is going to the "No code violations found" message from IF condition. So please help us to resolve where we are making mistake.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
