Skip to content

Commit

Permalink
Fix the pipeline (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
aravind-opsverse authored Feb 19, 2024
1 parent 90a42f8 commit 8f6a11a
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions script/check-quality-gate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,26 @@ printf '\n'

analysisId="$(jq -r '.task.analysisId' <<< "${task}")"
qualityGateUrl="${serverUrl}/api/qualitygates/project_status?analysisId=${analysisId}"
qualityGateStatus="$(curl --location --location-trusted --max-redirs 10 --silent --fail --show-error --user "${SONAR_TOKEN}": "${qualityGateUrl}" | jq -r '.projectStatus.status')"
qualityGateProjectStatus="$(curl --location --location-trusted --max-redirs 10 --silent --fail --show-error --user "${SONAR_TOKEN}": "${qualityGateUrl}" | jq '.projectStatus')"
qualityGateApiResponse=$(curl --location --location-trusted --max-redirs 10 --silent --fail --show-error --user "${SONAR_TOKEN}": "${qualityGateUrl}")
echo $qualityGateApiResponse > output.json

if [[ -n "${METRIC_NAME}" ]]; then
for metric in $(cat output.json | jq .projectStatus.conditions | jq .[].metricKey); do
echo $metric
if [[ "$metric" = "${METRIC_NAME}" ]]; then
metricValue="$(cat output.json | jq .projectStatus.conditions | jq .[].actualValue)"
set_output "${METRIC_NAME}" ${metricValue}
set_output "quality_gate_project_status" ${metricValue}
fi
done
else
qualityGateStatus="$(curl --location --location-trusted --max-redirs 10 --silent --fail --show-error --user "${SONAR_TOKEN}": "${qualityGateUrl}" | jq -r '.projectStatus.status')"
qualityGateProjectStatus="$(curl --location --location-trusted --max-redirs 10 --silent --fail --show-error --user "${SONAR_TOKEN}": "${qualityGateUrl}" | jq -r '.projectStatus.conditions')"
fi

dashboardUrl="$(sed -n 's/dashboardUrl=\(.*\)/\1/p' "${metadataFile}")"
analysisResultMsg="Detailed information can be found at: ${dashboardUrl}\n"

if [[ "${SET_SONAR_PROJECT_STATUS}" = "true" ]]; then
set_output "quality_gate_project_status" ${qualityGateProjectStatus}
fi
if [[ ${qualityGateStatus} == "OK" ]]; then
set_output "quality-gate-status" "PASSED"
success "Quality Gate has PASSED."
Expand Down

0 comments on commit 8f6a11a

Please sign in to comment.