githubgithub-actionsgithub-apirunner

How to get what the runner name is inside the github actions workflow?


I have a github actions workflow which contains below snippets.

runs-on:
  - ubuntu-latest
  - some-self-hosted-runner

Is there a way to get the value of runner like ubuntu-latest or some-self-hosted-runner inside the workflow so that I can conditionally branch the steps using if, else blocks?

I did try to get runner.os. But it's not giving the expected output.


Solution

  • You can use matrix for scenarios like this, such as having multiple runners, needing to run different combinations etc.

    jobs:
      <job-name>:
        strategy:
          matrix:
            os: [ubuntu-latest, some-self-hosted-runner]
        runs-on: ${{ matrix.os }}
        steps:
          - name: check os
            run: echo ${{ matrix.os }}