Skip to content
Latchkey

nick-fields/retry

Retry a flaky command with a timeout, instead of re-running the whole job.

Community actionCategory: Testing & CoverageLatest v4View on GitHub

What it does

nick-fields/retry wraps a shell command with retry logic: it enforces a per-attempt timeout, waits between attempts, and only fails the step after max_attempts is exhausted.

It can retry on any failure, only on timeout, only on error, or only on a specific exit code, and can run a cleanup command between attempts.

Usage

workflow (.yml)
steps:
  - uses: actions/checkout@v4
  - uses: nick-fields/retry@v4
    with:
      timeout_minutes: 10
      max_attempts: 3
      command: npm run test:e2e

Inputs

InputDescriptionDefaultRequired
commandThe command to run.-Yes
max_attemptsNumber of attempts to make before failing the step.3Yes
timeout_minutesMinutes to wait before an attempt times out. Specify either minutes or seconds, not both.-No
timeout_secondsSeconds to wait before an attempt times out. Specify either minutes or seconds, not both.-No
retry_wait_secondsSeconds to wait before the next retry.10No
retry_onEvent to retry on: any, timeout, or error.-No
on_retry_commandCommand to run before a retry (such as a cleanup script).-No

Outputs

OutputDescription
total_attemptsThe final number of attempts made.
exit_codeThe final exit code returned by the command.
exit_errorThe final error returned by the command.

Notes

A timeout is mandatory: set exactly one of timeout_minutes or timeout_seconds, or the action fails before running the command.

Retrying masks flakiness rather than fixing it, pair it with a test reporter so retried failures stay visible.

Common errors

  • Must specify either timeout_minutes or timeout_seconds inputs means neither timeout was set. One of the two is required.
  • Final attempt failed means the command failed on every attempt; the step then exits with the command's exit code. Check the log of the last attempt, not the first.

Security and pinning

  • The command runs with the job's full environment and token. Never interpolate untrusted input (PR titles, issue bodies) into it, and pin the action to a commit SHA.

Alternatives and related

Frequently asked questions

Can this retry a whole job or another action?
No. It retries a single shell command. To retry a uses: step or an entire job you need to re-run the job or restructure the logic into a command this action can wrap.
Running nick-fields/retry? Run it on Latchkey managed runners - self-healing and caching included. Start free → 30-day trial · No credit card