Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

Make a GitHub Actions step run after a failure, and keep the job failed

ErrorThe upload or cleanup step shows as skipped after a failed test step

Short 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.

  • Applies to GitHub Actions, ubuntu-latest
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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/*.yml
  2. 2Match what you see, then jump to its fix

    1. 1Steps after the failed one are shown as skipped.The later step has no status check, so it defaults to success()Fix
    2. 2A report or cleanup step is needed in both outcomes.The step must run on success and on failure, but not on cancelFix
    3. 3The step shows a red mark but the job and the run are green.continue-on-error turns the failure greenFix

What does the error look like?

  • The upload or cleanup step shows as skipped after a failed test step
  • The 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/*.yml

2Fix

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-status

Confirmed by docs.github.com

Did this fix it?

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/*.yml

2Fix

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.sh

3Verify

Run once green and once red: the report step runs both times, and a cancelled run skips it.

gh run list --limit 5

Confirmed by docs.github.com

Did this fix it?

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/*.yml

2Fix

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: false

3Verify

A failing required step now turns the run red; only the experimental entry stays allowed to fail.

gh run list --limit 5 --status failure

Confirmed by docs.github.com

Did this fix it?

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 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 fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.