How to get the workflow run ID? #26965
-
I would like to send a Telegram message containing the URL of a specific workflow run when it failed. I found how to send Telegram message (via appleboy/telegram-action), found the repository info using ${{ github.repository }} , but I still haven’t found how to get that specific workflow run ID. By ID, I mean the 12345 in https://github.com/foo/bar/actions/12345. How can I get the workflow run ID? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
Do you mean the run id in https://github.com/foo/bar/actions/ runs /12345.? There is a run_id property of github context. You could use ${{ github.run_id }} to get the run ID. |
Beta Was this translation helpful? Give feedback.
-
In case you need to extract it from the command line, you can use this script in bash: RUNID=$(gh api repos/$OWNER/$REPO/commits/$COMMIT_SHA/check-runs | jq -r '.check_runs[] | select(.name == "NAME_OF_YOUR_GITHUB_ACTIONS_WORKFLOW") | .html_url | capture("/runs/(?<number>[0-9]+)/jobs") | .number' | sed 's/"//g' | head -n 1) Full explanation on StackOverflow: https://stackoverflow.com/a/76465815/4441211 |
Beta Was this translation helpful? Give feedback.
-
How we can obtain run id if we dispatch workflow using api in powershell script? |
Beta Was this translation helpful? Give feedback.
-
A less hacky alternative to the above is to use the API endpoint for listing workflow runs and filtering by associated commit: gh api /repos/$OWNER/$REPO/actions/workflows/$WORKFLOW_FILE_OR_ID/runs \
--method GET -f head_sha=$COMMIT_SHA |
Beta Was this translation helpful? Give feedback.
@rffontenelle
Do you mean the run id in https://github.com/foo/bar/actions/ runs /12345.?
There is a run_id property of github context. You could use ${{ github.run_id }} to get the run ID.