patternbashModerate
Retry failed steps with a retry action or shell loop
Viewed 0 times
nick-fields/retry@v3
retryflakytransient failurenpm ciresiliencenetwork error
Problem
Network-dependent steps (npm install, Docker pull, API calls) fail transiently in CI, causing the entire pipeline to fail even though a retry would succeed. Rebuilding manually wastes time.
Solution
Use nick-fields/retry for step-level retries, or implement a shell retry loop:
Or a simple shell approach:
For flaky tests, consider pytest-rerunfailures or jest --testRepeats rather than retrying the whole step.
- uses: nick-fields/retry@v3
with:
timeout_minutes: 5
max_attempts: 3
retry_wait_seconds: 10
command: npm ciOr a simple shell approach:
- name: Install with retry
run: |
for i in 1 2 3; do
npm ci && break
echo "Attempt $i failed, retrying in 10s..."
sleep 10
doneFor flaky tests, consider pytest-rerunfailures or jest --testRepeats rather than retrying the whole step.
Why
Transient failures are a network reality in CI. Retrying at the step level avoids wasting the entire job run. Shell loops are dependency-free and easy to audit.
Gotchas
- Retrying tests that have side effects (database mutations, file writes) can leave state that causes the retry itself to fail differently
- Excessive retries mask real flakiness—track flaky test rates separately
- nick-fields/retry does not retry on specific exit codes by default; configure retry_on if needed
Revisions (0)
No revisions yet.