How to Retry a Failing Job in GitLab CI
GitLab retries a failing job automatically with the retry keyword, optionally scoped to specific failure types.
Set retry: to a max count, or use the object form with when: to retry only on certain failures (e.g. runner_system_failure, api_failure).
Retry only transient failures
Retry up to twice, but only for runner/system failures and script-timeout - not real test failures.
.gitlab-ci.yml
flaky-integration:
script:
- npm run test:integration
retry:
max: 2
when:
- runner_system_failure
- stuck_or_timeout_failure
- api_failureGotchas
- A bare
retry: 2retries on any failure, which can mask real bugs - scope it withwhen:where possible. maxis capped at 2 (so up to 3 total runs); higher values are rejected.- Retries re-run the whole job from scratch - non-idempotent side effects repeat.
Frequently asked questions
How do I retry a Failing Job in GitLab CI?
Set retry: to a max count, or use the object form with when: to retry only on certain failures (e.g. runner_system_failure, api_failure).
Retry only transient failures?
Retry up to twice, but only for runner/system failures and script-timeout - not real test failures.
Related guides
How to Set a Job Timeout in GitLab CISet a job timeout in GitLab CI with the timeout keyword, how it interacts with the project and runner timeout…
How to Cancel Redundant Pipelines in GitLab CICancel redundant GitLab CI pipelines with interruptible jobs plus auto-cancel redundant pipelines, and use re…
How to Cache Maven Dependencies in GitLab CISpeed up GitLab CI Java builds by caching the Maven local repository (.m2) keyed on pom.xml so dependencies a…