diff --git a/.github/workflows/trigger-gitlab-pipeline.yml b/.github/workflows/trigger-gitlab-pipeline.yml index e8c29cac..281d3e54 100644 --- a/.github/workflows/trigger-gitlab-pipeline.yml +++ b/.github/workflows/trigger-gitlab-pipeline.yml @@ -72,9 +72,12 @@ jobs: echo "[ Running pipline check after $SLEEP_DURATION_MINUTES minutes ]" sleep $(($SLEEP_DURATION_MINUTES*60)) + retry=1 job_status="" - until [[ $job_status == "success" || $job_status == "failed" || $job_status == "canceled" || $job_status == "skipped" ]] + until [[ $retry -gt 5 || $job_status == "success" || $job_status == "failed" || $job_status == "canceled" || $job_status == "skipped" ]] do + echo "Attempt: $retry" + downstream_pipeline_id=$(curl -sS --request GET --header "PRIVATE-TOKEN: $GITLAB_PAT" \ --url "$GITLAB_ENDPOINT/$GITLAB_PROJECT_ID/pipelines/$PIPELINE_ID/bridges" \ | jq -r '[ .[] | select( .name | contains("'"$DOWNSTREAM_PIPELINE_NAME"'")) ]' | jq -r '.[].downstream_pipeline.id') @@ -85,9 +88,14 @@ jobs: | jq -r '[ .[] | select( .name | contains("'"$DOWNSTREAM_JOB_NAME"'")) ]' | jq -r '.[].status') echo "($DOWNSTREAM_JOB_NAME) Job status: $job_status" - [[ $job_status == "running" ]] && sleep $(($CHECK_INTERVAL_MINUTES*60)) + if [[ $job_status == "running" ]]; then + retry=$((retry+1)) + sleep $(($CHECK_INTERVAL_MINUTES*60)) + fi done + [[ $retry -gt 5 ]] && echo "Number of retries exceeded, please head to the GitLab job to check what happened" && exit 1 + [[ $job_status == "canceled" ]] && echo "GitLab job was cancelled" [[ $job_status == "skipped" ]] && echo "GitLab job has stopped, please head to the GitLab job to trigger job manually"