Skip to content

Commit fc1c835

Browse files
committed
SONARXML-252 Wait for the sonarcloud compute engine to finish
1 parent 432effe commit fc1c835

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

.cirrus.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ sonar_shadow_scan_and_issue_replication_task:
6969
depends_on:
7070
- build
7171
# Only run when triggered by the cirrus-ci cron job named "nightly"
72-
only_if: $CIRRUS_CRON == "nightly"
72+
# TODO only_if: $CIRRUS_CRON == "nightly"
7373
eks_container:
7474
<<: *CONTAINER_DEFINITION
7575
cpu: 2

shadow-scan-and-issue-replication.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,49 @@ function download_iris() {
3535
--output "${IRIS_JAR_PATH}" "${IRIS_JAR_URL}"
3636
}
3737

38+
function sonarcloud_compute_engine_status_for_given_project() {
39+
local PROJECT_KEY="$1"
40+
curl --silent --fail-with-body --location --request GET \
41+
--header "Authorization: Bearer ${SHADOW_SONAR_TOKEN}" \
42+
--output - \
43+
"${SHADOW_SONAR_HOST_URL}/api/ce/component?component=${PROJECT_KEY}" | \
44+
jq -r '.current.status'
45+
}
46+
47+
function wait_for_sonarcloud_compute_engine_to_finish() {
48+
local MAX_WAIT_TIME_SECONDS="300" # Default to 5 minutes
49+
local SLEEP_INTERVAL_SECONDS="1"
50+
local ELAPSED_TIME=0
51+
local LAST_STATUS=""
52+
local STATUS
53+
54+
echo "Waiting for SonarCloud compute engine to finish for project key: ${SHADOW_PROJECT_KEY}"
55+
while (( ELAPSED_TIME < MAX_WAIT_TIME_SECONDS )); do
56+
STATUS=$(sonarcloud_compute_engine_status_for_given_project "${SHADOW_PROJECT_KEY}")
57+
if [[ "${STATUS}" != "${LAST_STATUS}" ]]; then
58+
echo -n " ${STATUS} "
59+
LAST_STATUS="${STATUS}"
60+
fi
61+
62+
if [[ "${STATUS}" == "PENDING" || "${STATUS}" == "IN_PROGRESS" ]]; then
63+
echo -n "."
64+
elif [[ "${STATUS}" == "FAILED" || "${STATUS}" == "CANCELED" ]]; then
65+
echo "\nERROR: SonarCloud compute engine finished with status: ${STATUS}"
66+
return 1
67+
elif [[ "${STATUS}" == "SUCCESS" ]]; then
68+
echo "\nSonarCloud compute engine finished successfully."
69+
return 0
70+
else
71+
echo "\nERROR: Unknown status: ${STATUS}"
72+
return 1
73+
fi
74+
sleep "${SLEEP_INTERVAL_SECONDS}"
75+
ELAPSED_TIME=$((ELAPSED_TIME + SLEEP_INTERVAL_SECONDS))
76+
done
77+
echo "\nERROR: Timeout reached after ${MAX_WAIT_TIME_SECONDS} seconds."
78+
return 1
79+
}
80+
3881
function run_iris() {
3982
local DRY_RUN="$1"
4083
java \
@@ -70,4 +113,5 @@ function run_iris_with_and_without_dry_run() {
70113

71114
build_and_analyze_the_project "$@"
72115
download_iris
116+
wait_for_sonarcloud_compute_engine_to_finish
73117
run_iris_with_and_without_dry_run

0 commit comments

Comments
 (0)