How do you make a job that only runs after a matrix job if all legs passed, and another that runs if any leg failed?
IntermediateConceptJobs, Steps, Matrix & Concurrency
Answer
needs on a matrix job waits for all legs, and result is aggregated.
publish:
needs: test # implicit success(): all legs passed
notify:
needs: test
if: ${{ failure() }} # any leg failed
runs-on: ubuntu-24.04
steps:
- run: echo "Tests failed on run ${{ github.run_id }}"
More on Jobs, Steps, Matrix & Concurrency
How does `needs` work, and what happens to a job whose dependency failed or was skipped?BeginnerWhat is the implicit `success()` in a job `if`, and why is `always()` usually the wrong fix?IntermediateWhat values can `needs.<job>.result` take?BeginnerHow does a matrix expand, and how are job names generated?BeginnerHow do `include` and `exclude` work in a matrix?IntermediateWhat do `fail-fast` and `max-parallel` do?Beginner