mirror of
https://github.com/SonarSource/sonarqube-quality-gate-action.git
synced 2026-09-25 14:38:33 +00:00
Add a polling timeout (#50)
The property timeout-minutes in a GitHub step is not supported in composed actions. So the workaround to stop the waiting for finishing the sonar scan is not working in such cases. To fix this issue, a polling timeout variable was introduced, which stops the waiting if the timeout is reached.
This commit is contained in:
@@ -8,12 +8,19 @@ if [[ -z "${SONAR_TOKEN}" ]]; then
|
||||
fi
|
||||
|
||||
metadataFile="$1"
|
||||
pollingTimeoutSec="$2"
|
||||
|
||||
|
||||
if [[ ! -f "$metadataFile" ]]; then
|
||||
echo "$metadataFile does not exist."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ ! $pollingTimeoutSec =~ ^[0-9]+$ || $pollingTimeoutSec -le 0 ]]; then
|
||||
echo "'$pollingTimeoutSec' is an invalid value for the polling timeout. Please use a positive, non-zero number."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ ! -z "${SONAR_HOST_URL}" ]]; then
|
||||
serverUrl="${SONAR_HOST_URL%/}"
|
||||
ceTaskUrl="${SONAR_HOST_URL%/}/api$(sed -n 's/^ceTaskUrl=.*api//p' "${metadataFile}")"
|
||||
@@ -37,7 +44,9 @@ fi
|
||||
task="$(curl --location --location-trusted --max-redirs 10 --silent --fail --show-error --user "${SONAR_TOKEN}": "${ceTaskUrl}")"
|
||||
status="$(jq -r '.task.status' <<< "$task")"
|
||||
|
||||
until [[ ${status} != "PENDING" && ${status} != "IN_PROGRESS" ]]; do
|
||||
endTime=$(( ${SECONDS} + ${pollingTimeoutSec} ))
|
||||
|
||||
until [[ ${status} != "PENDING" && ${status} != "IN_PROGRESS" || ${SECONDS} -ge ${endTime} ]]; do
|
||||
printf '.'
|
||||
sleep 5
|
||||
task="$(curl --location --location-trusted --max-redirs 10 --silent --fail --show-error --user "${SONAR_TOKEN}": "${ceTaskUrl}")"
|
||||
@@ -45,6 +54,11 @@ until [[ ${status} != "PENDING" && ${status} != "IN_PROGRESS" ]]; do
|
||||
done
|
||||
printf '\n'
|
||||
|
||||
if [[ ${status} == "PENDING" || ${status} == "IN_PROGRESS" ]] && [[ ${SECONDS} -ge ${endTime} ]]; then
|
||||
echo "Polling timeout reached for waiting for finishing of the Sonar scan! Aborting the check for SonarQube's Quality Gate."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
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')"
|
||||
|
||||
Reference in New Issue
Block a user