Join multiple jobs

Hey,
I want to run multiple jobs in parallel, and if one of them failed, I want to execute some commands (send slack or email notification to the team).
Any idea how to join all the jobs?

thanks

Hi @liorhasson,

You can define different jobs in the yaml file, jobs run in parallel by default.
You can search ‘slack’ in github marketplace, there’re many slack notification actions, you can choose one of them.
Code sample as below:

name: slack notification
on: [push]
jobs:
  job1:
    runs-on: [ubuntu-latest]
    steps:
      - name: test                   
        run: |
          echo this is job1!
      - name: fail step
        run: |
          exit 1
      - name: Slack Notification
        if: failure()                             # if there's any failure during the job, it will send out the slack message.
        uses: rtCamp/action-slack-notify@v2.0.2
        env:
          SLACK_CHANNEL: general
          SLACK_COLOR: '#3278BD'
          SLACK_ICON: https://github.com/rtCamp.png?size=48
          SLACK_MESSAGE: 'Post Content :rocket:'
          SLACK_TITLE: Post Title
          SLACK_USERNAME: rtCamp
          SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
  job2:
    runs-on: [ubuntu-latest]
    steps:
      - name: test
        run: |
          echo this is job2!
      - name: fail step
        run: |
          exit 1    
      - name: Slack Notification
        if: failure()                             # if there's any failure during the job, it will send out the slack message.
        uses: rtCamp/action-slack-notify@v2.0.2
        env:
          SLACK_CHANNEL: general
          SLACK_COLOR: '#3278BD'
          SLACK_ICON: https://github.com/rtCamp.png?size=48
          SLACK_MESSAGE: 'Post Content :rocket:'
          SLACK_TITLE: Post Title
          SLACK_USERNAME: rtCamp
          SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}

Besides, if you’d like to stop the workflow once any of jobs failed( skip other jobs), you can add a last step, using action ‘andymckay/cancel-action@0.2’ to cancel the workflow.
The step code sample as below:

      - name: cancel worflow
        if: failure() 
        uses: andymckay/cancel-action@0.2

If your jobs have same steps but only different parameter, you can also use jobs.<job_id>.strategy.matrix in the yaml, using jobs.<job_id>.strategy.fail-fast to cancel the other jobs if fail found.

Thanks.