Job ID is string in github.job, but integer in Actions API

I want to collect metrics about how long jobs take to complete. As job start and end times are not available in Actions, I need to use Github API and set up a process that:

  1. Posts the job ID from actions workflow to service X
  2. Service X requests job metadata using jobs API. From there I can read the start and end times.

Problem is that in Github Actions there seems to be no way to get the integer job ID value. ${{ github.job }} references the string label I have in the YAML file. This would be fine, but Github API for accessing job data only works with integer job ID.

So how should these things play together? Thanks

@ivokund,

The “github.job” is the key of a job object defined in the workflow definition (workflow file). It is fixed and not changed between workflow runs, unless you change it in the workflow file. The key also can be used as the job name in each workflow run, if you do not specify a name for the job.

In the Workflow Jobs API, the job here refers to an instance of the job object, the instance is generated within a workflow run (an instance of the workflow definition).
So, the job_id in the API is an unique number for each job instance within a repository.

If you view the title of the each Workflow Jobs API, you can find that all of them are “xxx for a workflow run” rather than “xxx for a workflow”.


Problem is that in Github Actions there seems to be no way to get the integer job ID value.

Yes, there is no any easy, fast way to get the integer job ID.

  1. If you do not specify job name, as I mentioned above, generally the key of the job object you defined in the workflow file will be used as the name of the job instance in each workflow run.
    So, to get the integer job ID, here is workaround:
  • Using “github.job” to get the key, also is name of the job instance.
  • Execute the “List jobs for a workflow run” API.
  • From the response context of the API, find the job via the name, then you can get the integer job ID from it.
  1. However, if you have specify the job name with another string, above workaround is not work. It is difficult to get the integer job ID. We seem have not available method to do this.

I recommend that you can directly report a feature request here to ask adding more useful properties (such as name and id) of the job instance in the job context or the github context.
That will allow you to directly interact with the appropriate engineering team, and make it more convenient for the engineering team to collect and categorize your suggestions.

1 Like

Thanks, this is what I suspected as well. I’ll make a feature request, thanks!