'Running a GitHub Actions step only if specific steps failed
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 }}"
Solution 1:[1]
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')
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | DᴀʀᴛʜVᴀᴅᴇʀ |