Steps.[step_id].outcome == 'failure' does not work

Hi GitHub,

This is a snippet from my job:

- name: Run Test With Coverage # running tests
    id: test_step
    run: pytest
- name: Dump steps context
    if: ${{ always() }}
        STEPS_CONTEXT: ${{ toJson(steps) }}
    run: echo "$STEPS_CONTEXT"
- name: Re Run Failed Tests
    if: ${{ steps.test_step.outcome == 'failure' }}
    run: LOG_LEVEL=info pytest --lf

The result of the context dump is:

  "eba14a9f4c4e4c77b1c5cb59ba84c279": {
    "outputs": {},
    "outcome": "success",
    "conclusion": "success"
  "172ab47f570540e084d249e62f611c31": {
    "outputs": {},
    "outcome": "success",
    "conclusion": "success"
  "test_step": {
    "outputs": {},
    "outcome": "failure",
    "conclusion": "failure"

However, the third step (re run failed tests) won’t execute.

  1. Why does the dump only contains 3 steps, even though I have about 10+ steps?
  2. What did I do wrong, and how I can I the steps execute?


The documentation on status check functions says:

You can use the following status check functions as expressions in if conditionals. A default status check of success() is applied unless you include one of these functions.

That’s why, you’ll need to add one of the other status check functions (I assume failure()) to the if condition.

Thank You!
I changed my if statement to: if: ${{ failure() && steps.test_step.outcome == 'failure' }} and it worked. I with this was in the documentation because it was frustrating to figure out.

I had used failure before, but I added black and isort and I wanted them to fail the workflow if the PR wasn’t compliant with them, but I didn’t want the rerun failed tests step to execute (which would’ve happened with if: {{ failure() }}

1 Like