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:
But, in the documentation of the contexts it says that it is String:
My question is, what is it or how could I obtain the context to obtain the job id, the integer value?
There is no straight way to do that - those are not the same values.
The only solution I know is to:
github.job
getting the key/repos/{owner}/{repo}/actions/runs/{run_id}/jobs
This information is not available in the github context level, however you can just filter out it, using a unique job information, like the runner.name. In this way you can get job id for any case, including matrix.
- name: Get Job ID from GH API
id: get-job-id
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
jobs=$(gh api repos/${{ github.repository }}/actions/runs/${{ github.run_id}}/attempts/${{ github.run_attempt }}/jobs)
job_id=$(echo $jobs | jq -r '.jobs[] | select(.runner_name=="${{ runner.name }}") | .id')
echo "job_id=$job_id" >> $GITHUB_OUTPUT
- name: Display Job ID
run: |
echo Job ID: ${{ steps.get-job-id.outputs.job_id }}
echo My full job URL is ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}/job/${{ steps.get-job-id.outputs.job_id }}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With