Running a job on every runner in GitHub Actions
Asked Answered
W

1

14

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!

Weimer answered 21/1, 2021 at 18:42 Comment(2)
Did you find an answer to this?Crossexamine
No, but I did have a reply from someone from the Github Support Community: github.community/t/running-a-job-on-every-runner-in-parallel/…Weimer
B
8

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
Bogie answered 26/1, 2022 at 14:33 Comment(2)
Very good answer. Checkout the syntax and explanation here: docs.github.com/en/actions/using-jobs/…Eldoria
this would work if you gave every runner you have a unique id and used that in the matrixVanessa

© 2022 - 2024 — McMap. All rights reserved.