Getting the run id of a run in Github Actions

I have a usecase where I want to share the log of the github action, sharing a github action log would be sharing something like https://github.com/org/repo/runs/284492795

Currently we only have GITHUB_SHA this shows the log in that SHA but the specific run is not shown, having the run id as a variable can help in better navigation of the logs from external services using Github Actions.

Export the run id in the run context or as an env variable somehow.

from this url:

https://github.com/org/repo/runs/284492795

i assume 284492795 is the run id.

12 Likes

+1…

Hi @geekodour @krasi-georgiev ,

You can try using the GitHub REST APIs to get the IDs of the runs in a workflow.

The following API is used to get all the runs in a specific workflow/check suite.

GET https://api.github.com/repos/<org>/<repo>/check-suites/<check_suite_id>/check-runs

From the Response body of the API you can get the IDs of the runs.

If you want to get the runs from multiple workflows/check suites, at first you can use the following API to get all the workflows/check suites in a specific repository.

GET https://api.github.com/repos/BrightRan/TestClock/commits/master/check-suites

From the Response body of the API you can get the IDs of the workflows/check suites.

More details about the GitHub REST API, please reference here: https://developer.github.com/v3/checks/

Yes, there is API for that, but that could not uniquely identify the current run-id.

See also https://github.community/t5/GitHub-Actions/Check-Suite-identifier-as-an-environment-variable/m-p/35498#M2240

1 Like

This seems a big ommision, coming from Azure Pipelines where we have build-ids and release-ids provided as builtin variables which uniquely identify the run, it’s left me a little lost.

I generally use these ids to tag build artifacts (e.g. container images) when building, and when releasing use the release run-id as a way to name my kubernetes/cloud resources, e.g. endpoints, Helm release names etc.

3 Likes

Thankyou for the response,

where do we get the <check_suit_id> from? but even if we do according to your reply we get a list of run id, which is not what is required. We just want the run-id of the current run. This I think should be passed to the runner context aswell.

2 Likes

In exactly this situation, need a unique number which increments each time a run in trigged for versioning outputted assets.

In the current Azure Devops build I use Build.BuildId ** ** so the version is v1.1.$BUILD_ID

https://docs.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml#build-variables

2 Likes

UPDATE : This is now available see here.

Thanks all. We’re working on this.

We’re improving API integration with runners + adding incrementing run ID’s for workflows. With new environment variables to make them easy to work with.

10 Likes

@mscoutermarsh wrote:

Thanks all. We’re working on this.

 

We’re improving API integration with runners + adding incrementing run ID’s for workflows. With new environment variables to make them easy to work with.

Is there an issue open that I can follow to know when this is ready?

Follow https://twitter.com/ghchangelog and we’ll be sharing there when it’s released.

Should be within the next month.

2 Likes

Please also expose the run’s check suite id as well.

Not the same thing, but related…

For authenticaiton purposes from the Action (calling out to an external service) it would be useful to have a Github signed token (Oauth?) which would be valid only during the time the Action is live.

Related in the since that rather than just a run ID there could  be a package including such an token.

2 Likes

Looks like ${{github.run_id}} is now available. You can also do ${{github.run_number}}.

I’ve been running this simple action step now and again to get new information on the github object:

steps:
      - name: Dump GitHub context
        env:
          GITHUB_CONTEXT: ${{ toJson(github) }}
        run: |
          echo "$GITHUB_CONTEXT"

This tends to have better information on what’s available than the docs.

4 Likes

Note that the run\_id in the GitHub context mentioned by @paul-sachs is the workflow run ID, not the Check Run ID.

You can get the Check Suite ID by passing in ${{ github.run\_id }} as a path parameter in the Get a Workflow Run API (https://developer.github.com/v3/actions/workflow_runs/#get-a-workflow-run) and reading the JSON response body’s check\_suite\_id property. But there’s still no way to get the Check Run ID.

The check_run is available via the Actions API on the Job.

Take a look at: https://developer.github.com/v3/actions/workflow_jobs/

We include the check_run_url. Which is the API path to get the associated check_run.

Ah. I did not notice that. Slightly confusing, it would be really nice to embed information on the check run id in the object itself.

What info would be helpful?

I haven’t messed with it yet, but if run_id is the workflow run, it would also be useful to have the specific check_run_id available as well. I might have just replied too quickly, so this might not be to relevant. 

2 Likes

Got it! Yeah, that makes sense. I’ll see about adding it.

Please keep me updated on how it goes when you play around with it. Interested in how it works for you.

3 Likes

I think it will be helpful because it’s going to be unique despite the re-run of the flow, different as the documentation says about GITHUB\_RUN\_ID:&nbsp;This number does not change if you re-run the workflow run.

Also, it can be really helpful to build the URL of the checks or if we can have as well the URL of the actual checks will be great when you are referencing those checks in a different place and the users can go directly to the checks and see the output.