Can I check a job status from a step that's in another job?


I have 2 jobs, both start at the same time. I don’t want to add dependency between them as job1 takes less time than job2 and a step from job2 needs job1 to be finished successfully before running.
How can I check job1 status from within a step that’s in job2?



In job2, you can try using API “List jobs for a workflow run” to monitor the status of job1.
This API will list all jobs in a workflow run, in the response (JSON-type), each object for the jobs contains the status and conclusion of the job. Here you may need using jq filter to read and get the required data from the response.
In job2, you also need to execute this API in a loop to get the fresh status of job1.
The following is an simple demo as reference:

    . . .
      ---- some steps in job1 ----

    . . .
      ---- some other steps in job2 ----

      - name: wait job1 completed
        id: job1_result
        shell: bash
        run: |
          while [ "$status" != "completed" ]
            response=$(curl --request GET \
            --url '${{ github.repository }}/actions/runs/${{ github.run_id }}/jobs' \
            --header 'Authorization: token ${{ secrets.GITHUB_TOKEN }}' \
            --header 'Accept: application/vnd.github.v3+json')
            status=$(echo $response | jq -r '.jobs[] | select(.name=="job1") | .status')
            echo $status
            if [[ $status == completed ]]; then
              conclusion=$(echo $response | jq -r '.jobs[] | select(.name=="job1") | .conclusion')
              echo $conclusion
              sleep 10s
        # The frequency of the API request is too high may cause error "API rate limit exceeded".
        # Using a sleep to reduce the frequency of loop.
          echo "::set-output name=status::$status"
          echo "::set-output name=conclusion::$conclusion"

      - name: step wait for job1
        if: ${{ steps.job1_result.outputs.status == 'completed' && steps.job1_result.outputs.conclusion == 'success' }}
        run: echo "run this step after job1 completed successfully"

Many thanks, I will try this!


How are things going?
Have you tried as my suggestion? Is it helpful for you?
Please try it, and any progress, feel free to tell me. Thanks.

Hi @brightran, I haven’t gotten to it yet, I’m planning on doing it today.
I will get back here with updates either way though.