Get status of parallel jobs into a single Webhook payload

I would like to check which of my  matrix runs passed and which didnt, and then use a webhook to send this information to a database.

Right now I have something like this:

name: BIOPYPIR-APPROVED
on: [push,pull_request]
jobs:
  build:
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        python-version: [3.5,3.6,3.7]
        os: [ubuntu-latest, macOS-latest]

        (run workflow...)

    - name: Workflow Webhook Action
      if: startsWith(matrix.os, 'ubuntu')
      uses: distributhor/workflow-webhook@v1
      with:
        webhook_url: ${{ secrets.WEBHOOK_URL }}
        data: |
         { "Job-Status" : "${{job.status}}"
            "Python-Versions" : "${{matrix.python-version}}",
            "OS" : "${{matrix.os}}"
           }

My goal is to send a single webhook that has the success/fail info for every job in my workflow. What’s the easiest way to do this?

Thanks.

Hi @benstear ,

The matrix job status and combination info can be checked from workflow jobs APIs here with GITHUB RUN_ID

You can add a 2nd job which needs matrix job, use ‘if: always()’ to make sure job2 will be executed when matrix job fails, code sample as below, my checkrun for your reference.

name: matrixjob
on: [push]

jobs:
  job1:
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-16.04, ubuntu-18.04]
        node: [6, 8]

    steps:
      - if: matrix.os=='ubuntu-16.04'
        name: sleep
        run: |
          sleep 20
      - if: matrix.os=='ubuntu-18.04'
        name: failstep
        run: |
          exit 1
      - uses: actions/setup-node@v1
        with:
          node-version: ${{ matrix.node }}

  job2:
    needs: [job1]
    if: always()
    runs-on: [ubuntu-latest]
    steps:
      - name: check the jobs # get the matrix job status and combination info
        run: |
          jobstatus=$(curl -X GET -s -u "admin:${{ secrets.PAT3 }}" https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/jobs | jq ".jobs[] | {job_status: .conclusion, matrix: .name}")
          echo $jobstatus

Now you get the info you wanted.

If string $jobstatus contains ‘failure’, you can simply mark the whole matrix job status as ‘fail’ ans tranfer to action ‘distributhor/workflow-webhoo’.

Note: action parameter doesn’t accept string $jobstatus, you can set is as env (set-env command)

Thank you @weide-zhou , this is perfect!

Two questions:

  1. Is it possible to access the step outputs or the artifacts from job 1 in job 2 in the same way?

  2. What is the PAT3 secret?

Hi @benstear ,

Thanks for your reply!

  1. step outputs cannot be shared into different jobs. 

   The only way to persist data between different jobs is ‘artifacts’. If you use artifacts to get the job status in each matrix parallel job, in job2, you need to download all of the artifacts, get the content and combine them to single file, transfer to action, it looks more complicated than the API.

  1. I create a personal access token with admin privilege to the repo, and make it as secrets PAT3.