Skip to content

Instantly share code, notes, and snippets.

@vctls
Created March 24, 2026 18:46
Show Gist options
  • Select an option

  • Save vctls/c217208d7922d81662736efce533273e to your computer and use it in GitHub Desktop.

Select an option

Save vctls/c217208d7922d81662736efce533273e to your computer and use it in GitHub Desktop.
Infinite Gitlab CI job retries
stages:
- test
- retry
test:
stage: test
script:
- ...
after_script:
- |
if [ $CI_JOB_STATUS != 'success' ]; then
curl -s --header "PRIVATE-TOKEN: ${CI_TOKEN}" \
"${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/pipelines/${CI_PIPELINE_ID}/jobs" \
| jq '.[] | select(.name == "retry") | .id' \
| xargs -I {} curl -s --header "PRIVATE-TOKEN: ${CI_TOKEN}" -X POST \
"${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/jobs/{}/retry"
fi
retry:
stage: retry
when: on_failure
script:
- |
curl -s --header "PRIVATE-TOKEN: ${CI_TOKEN}" \
"${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/pipelines/${CI_PIPELINE_ID}/jobs" \
| jq '.[] | select(.name == "test") | .id' \
| xargs -I {} curl -s --header "PRIVATE-TOKEN: ${CI_TOKEN}" -X POST \
"${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/jobs/{}/retry"
@vctls
Copy link
Copy Markdown
Author

vctls commented Mar 24, 2026

A Gitlab CI configuration to work around the retry count limit of Gitlab and retry jobs indefinitely until success or pipeline duration limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment