diff --git a/script/check-quality-gate.sh b/script/check-quality-gate.sh index b7d78fd..1074f0f 100755 --- a/script/check-quality-gate.sh +++ b/script/check-quality-gate.sh @@ -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."