12

For those that are familiar with Github Actions...

At present, when a job runs, it picks the most suitable runner for the job based on labels and repository (Using self-hosted runners in a workflow - GitHub Docs). My question is whether it is possible to run a single job on every runner that’s meets the requirements of a job.

For example, I have multiple runners, both self-hosted and hosted by Github; I have a job that contains a script that does the following when code is pushed to the repo:

  • Checks out the Git repo using actions/checkout@v2
  • Copies a file from the checked out repo to a user’s home directory

This “action” needs to take place on every runner that the action has access to.

I hope this makes sense!

riQQ
  • 9,878
  • 7
  • 49
  • 66
wegotoeleven
  • 139
  • 4

1 Answers1

5

According to official documentation you should use strategy option in your job, where you can define on which machine you want your job to run.

Although I didn't find specific use-case for combining github and self-hosted runners, I'd try something like this:

strategy:
  matrix:
    os: [ubuntu-18.04, ubuntu-20.04, self-hosted]
runs-on: ${{ matrix.os }}
steps:
  - uses: actions/checkout@v2
Ondřej Tůma
  • 184
  • 2
  • 6
  • 1
    Very good answer. Checkout the syntax and explanation here: https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs – KungFuPanda Nov 28 '22 at 21:57