Make a GitHub Actions step run after a failure, and keep the job failed
The upload or cleanup step shows as skipped after a failed test stepShort answer
A step with no if: condition gets success() by default, so it is skipped once any earlier step fails. Add if: ${{ failure() }} to run only after a failure, or if: ${{ !cancelled() }} to run after success or failure. The job still ends red. continue-on-error: true is different: it turns the failure green.
Fix it fast
1Find out which cause you have
Open the failed run and look at the step list. Skipped steps point to cause one; a green job with a red step icon points to cause three.
grep -n -E "if:|continue-on-error" .github/workflows/*.yml2Match what you see, then jump to its fix
- 1
Steps after the failed one are shown as skipped.The later step has no status check, so it defaults to success()Fix - 2
A report or cleanup step is needed in both outcomes.The step must run on success and on failure, but not on cancelFix - 3
The step shows a red mark but the job and the run are green.continue-on-error turns the failure greenFix
- 1
What does the error look like?
The upload or cleanup step shows as skipped after a failed test stepThe job is green even though a step failed (continue-on-error)
Cause 1 of 3
The later step has no status check, so it defaults to success()
1Check
If an if: condition contains none of the status check functions, GitHub applies success(), which means every previous step passed.
grep -n -B2 -A6 "upload-artifact" .github/workflows/*.yml2Fix
Add failure() to run the step only after a failure. The job keeps its failed result.
- name: Run tests
run: npm test
- name: Upload logs
if: ${{ failure() }}
uses: actions/upload-artifact@v4
with:
name: test-logs
path: logs/3Verify
Make the test step fail on purpose: the upload step runs and the job still shows as failed.
gh run watch --exit-statusConfirmed by docs.github.com
Cause 2 of 3
The step must run on success and on failure, but not on cancel
1Check
failure() alone skips the step when everything passed. always() runs even when the workflow is cancelled, which the docs warn can cause hangs for critical tasks.
grep -n "always()" .github/workflows/*.yml2Fix
Use !cancelled() for steps that should run after success or failure. Keep always() for cleanup that must run even after a cancel.
- name: Publish test report
if: ${{ !cancelled() }}
run: ./publish-report.sh3Verify
Run once green and once red: the report step runs both times, and a cancelled run skips it.
gh run list --limit 5Confirmed by docs.github.com
Cause 3 of 3
continue-on-error turns the failure green
1Check
continue-on-error: true on a step prevents the job from failing when that step fails. On a job, it prevents the workflow run from failing.
grep -n -B3 "continue-on-error" .github/workflows/*.yml2Fix
Remove continue-on-error where you want a red result, and use failure() or !cancelled() to run the later steps. Keep it only for steps whose failure should not matter, such as an experimental matrix entry.
runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.experimental }}
strategy:
fail-fast: false3Verify
A failing required step now turns the run red; only the experimental entry stays allowed to fail.
gh run list --limit 5 --status failureConfirmed by docs.github.com
How do I stop it coming back?
- Put upload-artifact and notification steps behind an explicit if: so they run when you need them.
- Use !cancelled() instead of always() unless the step really must run after a cancel.
- Limit continue-on-error to jobs you have named as allowed to fail, such as an experimental matrix entry.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Related fixes
Servers
A local composite action in GitHub Actions cannot be found
The action folder is in the repository but the runner reports that its action.yml cannot be found
A local action is read from the checked-out repository.
3 causes, each with a fixServers
A GitHub Actions workflow builds the Docker image but cannot push it
The push step fails right after the login step
Four things stop a push from GitHub Actions: build-push-action does not push unless push is true, the Docker Hub login used a password instead of an access token, the workflow token lacks packages write for ghcr.io, or the run comes from a fork, where the token is read-only.
4 causes, each with a fixServers
A GitHub Actions step with shell: pwsh or powershell fails on Linux
shell: powershell on a Linux runner
GitHub starts a step with the shell name you give.
3 causes, each with a fixServers
A self-hosted GitHub Actions runner goes offline or stops by itself
Runner status in Settings > Actions > Runners shows Offline
GitHub marks a runner Offline when the machine is down, the runner application is not running, or it cannot reach GitHub.
3 causes, each with a fixServers
GitHub Actions step fails writing to GITHUB_OUTPUT
Error: Invalid format '...'
The runner reads GITHUB_OUTPUT line by line, and every entry must be name=value or a name<<DELIMITER block.
3 causes, each with a fixServers
poetry command not found right after installing it in a GitHub Actions step
Poetry installs without error in one step, and the next step cannot find it
The official installer puts the poetry command in $HOME/.local/bin, which is not always on PATH.
3 causes, each with a fix