From 1d63721458447be0fb6703db16de9f6a1056093e Mon Sep 17 00:00:00 2001 From: Sergio Date: Mon, 13 Jan 2025 13:58:01 +0100 Subject: [PATCH] Wait for completion --- .github/workflows/build-any-ib.yml | 38 ++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build-any-ib.yml b/.github/workflows/build-any-ib.yml index 72ab6bfb..ed721090 100644 --- a/.github/workflows/build-any-ib.yml +++ b/.github/workflows/build-any-ib.yml @@ -54,7 +54,7 @@ jobs: # USE_REMOTE_STORE: "true" steps: - - name: Launch the build-any-ib job in Jenkins + - name: Launch the build-any-ib job in Jenkins and wait for completion run: | # Login against SSO TOKEN="$(curl --location -X POST "$SSO_AUTH_URL" \ @@ -64,9 +64,39 @@ jobs: --data-urlencode "client_secret=$CLIENT_SECRET" \ --data-urlencode "audience=$TARGET_APP" | jq -r '.access_token')" - # Trigger the Jenkins job - curl "$JENKINS_URL/job/$JOB_NAME/buildWithParameters" \ + # Trigger the Jenkins job and get the queue item location + QUEUE_URL=$(curl -w "%{redirect_url}" -s -o /dev/null "$JENKINS_URL/job/$JOB_NAME/buildWithParameters" \ -H "Authorization: Bearer $TOKEN" \ --data "PACKAGE_NAME=$PACKAGE_NAME" \ --data "ALIDIST_SLUG=$ALIDIST_SLUG" \ - --data "ARCHITECTURE=$ARCHITECTURE" + --data "ARCHITECTURE=$ARCHITECTURE") + + # Poll the queue item until we get the actual job URL + while true; do + QUEUE_RESPONSE=$(curl -s "$QUEUE_URL/api/json" -H "Authorization: Bearer $TOKEN") + if echo "$QUEUE_RESPONSE" | jq -e '.executable.url' > /dev/null; then + BUILD_URL=$(echo "$QUEUE_RESPONSE" | jq -r '.executable.url') + break + fi + echo "Waiting for job to start..." + sleep 10 + done + + echo "Job started at: $BUILD_URL" + + while true; do + JOB_STATUS=$(curl -s "$BUILD_URL/api/json" -H "Authorization: Bearer $TOKEN" | jq -r '.result') + if [ "$JOB_STATUS" = "SUCCESS" ]; then + echo "Job completed successfully!" + exit 0 + elif [ "$JOB_STATUS" = "FAILURE" ] || [ "$JOB_STATUS" = "ABORTED" ]; then + echo "::error::Jenkins job failed with status: $JOB_STATUS" + exit 1 + elif [ "$JOB_STATUS" = "null" ]; then + echo "Job is still running..." + sleep 30 + else + echo "::error::Unknown Jenkins job status: $JOB_STATUS" + exit 1 + fi + done