Skip to content
Latchkey

How to Choose Job-Level vs Test-Level Retry in CI

Retry the whole job when the runner or environment flaked, and retry a single test when the test itself is flaky; matching the level to the cause avoids wasted minutes.

Job-level retry (rerunning the job) is right for infrastructure flakes: network blips, runner loss, a service that was not ready. Test-level retry is right when one test is timing-sensitive. Blanket job retries are expensive and mask which test is at fault.

When to use which

SymptomRetry levelWhy
Runner lost, network timeoutJobEnvironment flaked, not the test
One test times out intermittentlyTestCheaper, isolates the culprit
Whole suite fails to startJobSetup or dependency issue
Assertion fails randomlyFix itRetry hides a real bug

Job-level retry

.github/workflows/ci.yml
steps:
  - uses: nick-fields/retry@v3
    with:
      max_attempts: 2
      timeout_minutes: 20
      command: npm test

Gotchas

  • A job retry reruns every test, so it is far more expensive than retrying one test.
  • Job retries hide which test flaked; use test-level retry when you can pinpoint it.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →