mirror of
https://github.com/SonarSource/sonarqube-quality-gate-action.git
synced 2026-09-30 08:58:31 +00:00
Display dashboard URL if qualityGateStatus is WARN or ERROR
This commit is contained in:
@@ -43,21 +43,24 @@ until [[ ${status} != "PENDING" && ${status} != "IN_PROGRESS" ]]; do
|
||||
task="$(curl --location --location-trusted --max-redirs 10 --silent --fail --show-error --user "${SONAR_TOKEN}": "${ceTaskUrl}")"
|
||||
status="$(jq -r '.task.status' <<< "$task")"
|
||||
done
|
||||
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')"
|
||||
|
||||
printf '\n'
|
||||
dashboardUrl="$(sed -n 's/dashboardUrl=\(.*\)/\1/p' "${metadataFile}")"
|
||||
analysisResultMsg="Detailed information can be found at: ${dashboardUrl}\n"
|
||||
|
||||
if [[ ${qualityGateStatus} == "OK" ]]; then
|
||||
set_output "quality-gate-status" "PASSED"
|
||||
success "Quality Gate has PASSED."
|
||||
elif [[ ${qualityGateStatus} == "WARN" ]]; then
|
||||
set_output "quality-gate-status" "WARN"
|
||||
warn "Warnings on Quality Gate."
|
||||
warn "Warnings on Quality Gate.${reset}\n\n${analysisResultMsg}"
|
||||
elif [[ ${qualityGateStatus} == "ERROR" ]]; then
|
||||
set_output "quality-gate-status" "FAILED"
|
||||
fail "Quality Gate has FAILED."
|
||||
fail "Quality Gate has FAILED.${reset}\n\n${analysisResultMsg}"
|
||||
else
|
||||
set_output "quality-gate-status" "FAILED"
|
||||
fail "Quality Gate not set for the project. Please configure the Quality Gate in SonarQube or remove sonarqube-quality-gate action from the workflow."
|
||||
|
||||
@@ -81,6 +81,7 @@ teardown() {
|
||||
export SONAR_TOKEN="test"
|
||||
echo "serverUrl=http://localhost:9000" >> metadata_tmp
|
||||
echo "ceTaskUrl=http://localhost:9000/api/ce/task?id=AXlCe3gsFwOUsY8YKHTn" >> metadata_tmp
|
||||
echo "dashboardUrl=http://localhost:9000/dashboard?id=project&branch=master" >> metadata_tmp
|
||||
|
||||
#mock curl
|
||||
function curl() {
|
||||
@@ -100,12 +101,14 @@ teardown() {
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "${github_out_actual}" = "quality-gate-status=WARN" ]]
|
||||
[[ "$output" = *"Warnings on Quality Gate."* ]]
|
||||
[[ "$output" = *"Detailed information can be found at: http://localhost:9000/dashboard?id=project&branch=master"* ]]
|
||||
}
|
||||
|
||||
@test "fail when Quality Gate status ERROR" {
|
||||
export SONAR_TOKEN="test"
|
||||
echo "serverUrl=http://localhost:9000" >> metadata_tmp
|
||||
echo "ceTaskUrl=http://localhost:9000/api/ce/task?id=AXlCe3gsFwOUsY8YKHTn" >> metadata_tmp
|
||||
echo "dashboardUrl=http://localhost:9000/dashboard?id=project&branch=master" >> metadata_tmp
|
||||
|
||||
#mock curl
|
||||
function curl() {
|
||||
@@ -125,6 +128,7 @@ teardown() {
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "${github_out_actual}" = "quality-gate-status=FAILED" ]]
|
||||
[[ "$output" = *"Quality Gate has FAILED."* ]]
|
||||
[[ "$output" = *"Detailed information can be found at: http://localhost:9000/dashboard?id=project&branch=master"* ]]
|
||||
}
|
||||
|
||||
@test "pass when Quality Gate status OK" {
|
||||
@@ -150,6 +154,7 @@ teardown() {
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "${github_out_actual}" = "quality-gate-status=PASSED" ]]
|
||||
[[ "$output" = *"Quality Gate has PASSED."* ]]
|
||||
[[ "$output" != *"Detailed information can be found at:"* ]]
|
||||
}
|
||||
|
||||
@test "pass when Quality Gate status OK and status starts from IN_PROGRESS" {
|
||||
|
||||
Reference in New Issue
Block a user