Skip to content

Commit

Permalink
Wait for completion
Browse files Browse the repository at this point in the history
  • Loading branch information
singiamtel committed Jan 13, 2025
1 parent 77913e7 commit 1d63721
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions .github/workflows/build-any-ib.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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" \
Expand All @@ -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

0 comments on commit 1d63721

Please sign in to comment.