How to get the GitHub CI job build id (check_run_id)?

2.7k Views Asked by At

I am using build.cake file tasks with PowerShell script on the windows machine for GitHub CI. Am trying to get the check_run_id via GitHub Actions in the workflows .yml file. Is that possible?

i.e. https://github.com/Siddharth/my-project/pull/15/checks?check_run_id=2508655272

I need the id(2508655272) value in workflows.yml file. I have attached my workflow file.

I have tried to get check_run_id value from the GitHub parameter itself, checked the GitHub documentation. There is no option found to get the check_run_id directly.

Is there any way to get check_run_id?

Could you suggest a solution for how to achieve this in my workflow .yml file or any other alternate way to get it?

enter image description here

1

There are 1 best solutions below

0
On

It might be too late to you on the update for this query.

I had found the below approach to get the exact value. It was not quiet easy one with any direct environment variable or with action. Basically use the actions GitHub API with run_id.

Below is a snippet of GitHub-action step.

- run: |
    URI="https://api.github.com"
    API_HEADER="Accept: application/vnd.github.v3+json"
    AUTH_HEADER="Authorization: token ${{ secrets.GITHUB_TOKEN }}"
      
    body=$(curl -sSL -H "${AUTH_HEADER}" -H "$API_HEADER" "$URI/repos/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}/jobs")
    url=$(echo "$body" | jq .jobs | jq .[-1] | jq .html_url)
    id=$(echo "$body" | jq .jobs | jq .[-1] | jq .id)
    sha=$(echo "$body" | jq .jobs | jq .[-1] | jq -r .head_sha)
      
    echo ::set-output name=checkid::$id
  id: checkRunId
 ...
 ...

And then use ${{ steps.checkRunId.outputs.checkid }} output variable wherever you want to reference in other steps..

Please vote the answers if this is helping you.