- 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 }}
Job ID may be obtained with `curl` command (piped to `jq`):
curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}/attempts/${GITHUB_RUN_ATTEMPT}/jobs | jq .jobs[].id
where all ENVs `GITHUB_*` should be accessible inside workflow by default
PS `jobs` value is a list so multiple IDs may be returned
for a matrix strategy, although not pretty this will get the html url to the proper matrix job (in this example, the "name" of each individual matrix job is `matrix.region`):
gh api repos/${{ github.repository }}/actions/runs/${{ github.run_id}}/attempts/${{ github.run_attempt }}/jobs | jq -r '.jobs | map(select(.name | contains("${{ matrix.region }}"))) | .[0].html_url'
example:
example-job:
name: ${{ matrix.region }}
runs-on: ubuntu-latest
strategy:
matrix:
region: ["us-east-1", "us-west-2"]
- name: example-matrix-step
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
job_id=$(gh api repos/${{ github.repository }}/actions/runs/${{ github.run_id}}/attempts/${{ github.run_attempt }}/jobs | jq -r '.jobs | .[0].id')
matrix_job_html_url=$(gh api repos/${{ github.repository }}/actions/runs/${{ github.run_id}}/attempts/${{ github.run_attempt }}/jobs | jq -r '.jobs | map(select(.name | contains("${{ matrix.region }}"))) | .[0].html_url')
matrix_id=$( sed 's/.*\jobs\///' <<<$matrix_job_html_url)
echo "matrix job html url: $matrix_job_html_url"
echo "matrix id: $matrix_id" # i doubt this is of any use. in the github response this id is only present as part of the html_url
echo "job id: $job_id"
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 }}