9

I’d like to run a step only if specific previous steps FAILED with Exit Code different from Zero. I’ve tried the code below but it not working. How can I do that?

- name: JobA
  id: seedBuild
  run: |
        echo "::set-output name=exit_code::$(echo -n "$?")"

- name: JobB
  id: allJobs
  run: |
        echo "::set-output name=exit_code::$(echo -n "$?")"

- name: Debug Job Failure
  run: |
        echo "******** Job Logs from ********"
  if: "${{ steps.seedBuild.outputs.exit_code != 0 || steps.allJobs.outputs.exit_code != 0 }}"

1 Answer 1

20

Use the step's outcome steps.<step_id>.outcome:

code:

- name: JobA
  id: seedBuild
  run: |
        echo "failing on purpose"
        exit 1

- name: JobB
  id: allJobs
  run: |
        echo "::set-output name=exit_code::$(echo -n "$?")"

- name: Debug Job Failure
  run: |
        echo "******** Job Logs from ********"
  if: always() && (steps.seedBuild.outcome == 'failure' || steps.allJobs.outcome == 'failure')
Sign up to request clarification or add additional context in comments.

1 Comment

If, like me, you wonder why the condition includes always() &&, you can find the explanation in Status check functions: A default status check of success() is applied unless you include one of these functions.. In other words, GitHub inserts success() && unless you call always(), canceled(), or failure().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.