Deep Links to GitHub Actions Job Logs
Sources:
Overview
In GitHub Actions, you can rather easily create a link to the current workflow run:
However, it’s not as easy to link to a specific job within that workflow run. The variable ${{
github.job
}}
says it contains a job ID, but in this case it means the key from your workflow:
To link to the job logs, you can use the GitHub CLI which is available on all GitHub-hosted runners:
You need to provide the GH_TOKEN
environment variable for the CLI tool. If you’ve modified the default token permissions, you need at least read access to actions:
The CLI tool determines the repo from the current working directory. If you haven’t performed an actions/checkout
step, or you are referencing a different repo, pass the relevant flag to the CLI tool:
The JQ filter selects the job by name. If you don’t want to hardcode the job name, you need a further API call:
Linking back to Pull Requests
This URL can be useful when posting comments in a Pull Request. By default it doesn’t link to the PR, but you can add the ?pr
query string parameter to add a backlink:
Expanding the Logs for a Specific Step
Within the job there are a number of ordered steps. To expand the logs for a specific step, pass the ?check_suite_focus
query string param as well as a fragment like #step:x:y
, corresponding to the step number and line number. The step number is based on the order, so you can use the API for that too:
If you run this example, you might find that the URL step happens so quickly after the test step that the API response doesn’t contain the previous step’s result yet. You can either perform the API call a little later in the job, in a separate dependent job, or add a small sleep
before calling the API.
Inspired by Grant G’s answer on Stack Overflow.
Appendix
Note created on 2024-04-30 and last modified on 2024-04-30.
See Also
Backlinks
(c) No Clocks, LLC | 2024
Resources
Appendix
Note created on 2024-04-30 and last modified on 2024-04-30.
Backlinks
(c) No Clocks, LLC | 2024