Detect Self-Hosted Runner or GitHub Hosted Runner in GitHub Action Workflow #48359
-
Select Topic AreaQuestion BodyWe are generating a general GitHub Action Workflow that can be used on self-hosted runners and GitHub-hosted runners. As a result, we want to detect if the workflow is currently executing on a self-hosted runner to use this as a condition in an Unfortunately, we did not find a way to access the runner's labels nor any other flag or environment variable to detect if we are running the code on a self-hosted runner or on GitHub-provided runners. Are we missing a crucial detail there, or is there any mechanism to detect if a workflow is running on a GitHub-hosted runner or a self-hosted runner? We greatly appreciate any input and help with this! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Per @maskati https://github.com/orgs/community/discussions/48359#discussioncomment-9059557, it's now possible to detect this directly (and will hopefully be eventually documented for github/docs#32443) Previously... You'll probably want The self-hosted runners should have names that don't start with |
Beta Was this translation helpful? Give feedback.
-
There seems to be a context property |
Beta Was this translation helpful? Give feedback.
Per @maskati https://github.com/orgs/community/discussions/48359#discussioncomment-9059557, it's now possible to detect this directly (and will hopefully be eventually documented for github/docs#32443)
Previously...
https://docs.github.com/en/actions/learn-github-actions/contexts#example-contents-of-the-runner-context
You'll probably want
runner.name
The self-hosted runners should have names that don't start with
GitHub Actions
. (If your self-hosted runners names' start with that, you're doing something wrong, and you should fix that...)