Obtain job id from a workflow run using contexts

Viewed 1065

I have a problem, when I want to get the job id using the GitHub context in yaml file, it responds with a String:

  - name: Test
    run: |
      sendEmail ${{github.job]}

I obtain this response:

sendEmail Job_Test

In the GitHub documentation for the API, it says the following, which is an Integer field: enter image description here

But, in the documentation of the contexts it says that it is String: enter image description here

My question is, what is it or how could I obtain the context to obtain the job id, the integer value?

2 Answers

There is no straight way to do that - those are not the same values.

The only solution I know is to:

  1. read github.job getting the key
  2. get list of jobs for a workflow using API: /repos/{owner}/{repo}/actions/runs/{run_id}/jobs
  3. find the job by the name and get id as int value

There's a GitHub action to solve this problem: https://github.com/marketplace/actions/github-actions-job_id-parser

 - name: Get Current Job Log URL
    uses: Tiryoh/gha-jobid-action@v0
    id: jobs
    with:
      github_token: ${{ secrets.GITHUB_TOKEN }}
      job_name: ${{ github.job }}

- name: Output Current Job Log URL
  run: echo ${{ steps.jobs.outputs.html_url }}
Related