How to Retry a Flaky Script in GitHub Actions
A retry action re-runs a flaky script a few times with backoff before giving up, absorbing transient hiccups.
Wrap the command in nick-fields/retry, setting attempt count, per-attempt timeout, and wait. Reserve retries for genuinely transient failures, not real bugs.
Steps
- Replace the brittle
run:with the retry action. - Set
max_attempts,timeout_minutes, andcommand. - Log attempts so you can find and fix the root cause later.
Workflow
.github/workflows/ci.yml
steps:
- uses: nick-fields/retry@v3
with:
max_attempts: 3
timeout_minutes: 10
retry_wait_seconds: 15
command: ./scripts/integration-test.shGotchas
- Retrying masks flakiness; track which scripts retry so you can fix the underlying cause.
- Latchkey managed runners auto-retry transient infrastructure failures, so retries can focus on your own flaky steps.
Related guides
How to Make a Script Fail the Job on Error in GitHub ActionsEnsure a failing GitHub Actions script fails the job by exiting non-zero, since GitHub only marks a run step…
How to Run a pre-commit Check Script in GitHub ActionsEnforce the same pre-commit hooks in GitHub Actions that developers run locally by installing pre-commit and…