Getting the run id of a run in Github Actions

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. 

run_id is available in the GitHub context and as an environment variable (GITHUB_RUN_ID) on the runner.

GitHub Context: 

Variable: github.run_id

Docs: https://help.github.com/en/actions/automating-your-workflow-with-github-actions/contexts-and-expression-syntax-for-github-actions#github-context

Environment variable: 

Variable: GITHUB_RUN_ID

Docs: https://help.github.com/en/actions/automating-your-workflow-with-github-actions/using-environment-variables#default-environment-variables

4 Likes

sorry, I mean check\_run\_id but I found it doesn’t change if the action is re-run. So, I’m wondering if there’s something that can work as unique id per run? something similar to the possible id that the URL is using every time you run or re-run a job.

1 Like

it would be very helpful to have the _check\_run\_id_ or _job\_id_, so i could add specific annotations to the current _check\_run_

4 Likes