github-actionsgithub-api

Obtain job id from a workflow run using contexts


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?


Solution

  • 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