In a GitHub Actions workflow there are context variables for the current run ID and the current job name. These are sufficient to build a URL like this:
https://github.com/REPO/actions/runs/RUN_ID
This URL takes you to the following page:
I’d like to take the user to the page that would be accessed by clicking the “Import” job in the screenshot above, which has a URL like this:
https://github.com/REPO/actions/runs/RUN_ID/job/JOB_ID
This page looks like this:
I cannot find this JOB_ID anywhere in the context variable documentation. There is github.job
, but this gives a job name like “import”, which leads to a 404 if I put it in the URL above. There is also job.container.id
, but this seems to be an unrelated ID, and doesn’t work.
How can I construct the URL for the page in the second screenshot above?
1
The GitHub CLI provides a convenience function for this to inspect a workflow run:
gh run view "$GITHUB_RUN_ID"
You can request the jobs with
gh run view "$GITHUB_RUN_ID" --json jobs
which returns something like
{
"jobs": [
{
"completedAt": "2024-09-04T16:55:29Z",
"conclusion": "skipped",
"databaseId": 29683129691,
"name": "Some name",
"startedAt": "2024-09-04T16:55:29Z",
"status": "completed",
"steps": [],
"url": "https://github.com/{owner}/{repo}/actions/runs/{runID}/job/{jobID}"
}
]
}
Since you’re interested in the job URL, you could get it directly with something like
gh run view "$GITHUB_RUN_ID" --json jobs
--jq '.jobs | map(select(.name == "Import")) | first.url'
I’m not sure at which point this becomes available during a run, though.
6