get status of multiple jobs in the same workflow

Hello folks,

I have the workflow that contains 3 jobs, and I want to have 4th job that will send a slack message for me.

Could you please advise how to get the status of all jobs and their statuses that currently is on workflow.

The suggestion about putting all the jobs in one not an option

name: CI
on:
  push:
    branches:
      - master
jobs:
  one:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - run: echo "one"
  two:
    runs-on: ubuntu-latest
    steps:
      - run: echo "two"
  five:
    runs-on: ubuntu-latest
    needs: [one, two]
    if: always()
    steps:
      - run: echo "How to know the status of execution of jobs.one and jobs.two?"

The one thing that I found is using of Check API https://developer.github.com/v3/activity/events/types/#checksuiteevent

but this approach looks like a dirty workaround

Now, github actions provide workflow jobs APIs , you could use it to list all the jobs of a workflow run. 

https://developer.github.com/v3/actions/workflow_jobs/#list-jobs-for-a-workflow-run

And there is an environment variable GITHUB_RUN_ID you could use to get the current workflow run id. 

You could get the conclusion element value for job status. 

There is another method to pass job status through artifacts, for more information, please check BrightRan’s solution here: 

https://github.community/t5/GitHub-Actions/How-get-the-status-of-previous-jobs/m-p/45511#M6237 

Take a look at the Workflow Conclusion Action. It checks the status of the other jobs in your workflows, and will create an environment variable with a rolled up status. It works well if you need to do something conditionally on the basis of the other jobs.

https://github.com/marketplace/actions/workflow-conclusion-action

Did you find a reasonable solution to this?

Here’s my solution:


jobs:

  job0:

    name: job0

    outputs:

      job-status: ${{ job.status }}

  job1:

    name: job1

    outputs:

      job-status: ${{ job.status }}

  job2:

    name: job1

    needs:

      - job0

      - job1

    steps:

      - name: check job statuses

         run: |

           if [["${{ needs.job0.outputs.job-status }}" == "Success" && "${{ needs.job1.outputs.job.status }} == "Success"]]; then

             echo "Both jobs passed!"

          fi

Using the GITHUB_RUN_ID looks a good solution, however this is the run id and not the job id. What if have two jobs, how can we can get the right conclusion assuming the RUN_ID is the same?