Sub topic 4
Sending jobs to the right runner with labels
This chapter assumes you can read a GitHub Actions workflow (on, jobs, steps, runs-on) and that you have registered a self-hosted runner. Registration is covered in the previous chapter. Here you will see how GitHub decides which runner receives a job.
How labels route jobs
A label is a text tag attached to a runner. A job lists the labels it needs in runs-on. GitHub offers the job only to runners that carry every label in that list. Matching is an AND, not an OR.
Every self-hosted runner gets some labels automatically:
| Label | Meaning |
|---|---|
| `self-hosted` | The runner is not GitHub-hosted |
| `linux`, `windows`, `macOS` | The operating system |
| `x64`, `arm`, `arm64` | The CPU architecture |
You can add custom labels when you register the runner, for example --labels ephemeral,gpu.
A workflow that targets labels
This workflow from the plan selects runners by four labels and limits the token to read access.
name: test
on: pull_request
permissions:
contents: read
jobs:
test:
runs-on: [self-hosted, linux, x64, ephemeral]
steps:
- uses: actions/checkout@v4
- run: make testOnly a runner with self-hosted, linux, x64 and ephemeral can run the test job. A runner that has the first three but not ephemeral is ignored.
Adding the label at registration
The label is attached when the runner is configured. The --labels option adds custom labels on top of the automatic ones.
./config.sh \
--url https://github.com/OWNER/REPO \
--token REGISTRATION_TOKEN \
--name "runner-$(hostname)-$(date +%s)" \
--labels ephemeral \
--ephemeral \
--unattended
./run.shNote that --labels ephemeral is only a tag. It does not make the runner ephemeral. The --ephemeral flag does that. The label is a convention that lets workflows ask for that kind of runner by name.
Common errors
- The job waits in "Queued" forever. No online runner carries every label. Check for a typo, a runner that is offline, or a label that was never added. GitHub does not report a missing label as an error. The job simply waits.
- Case and spelling. Labels are matched without regard to case in most setups, but a stray space or different word (
ephemeralversusephemeral-runner) means no match. Copy the label from the runner's settings page. - Too few labels.
runs-on: self-hostedmatches every self-hosted runner in scope, including old persistent ones. Always add OS, architecture, and a custom label that describes the runner's role. - Wrong scope. Labels only route among runners the repository can see. A runner registered to a different repository, or in a runner group the repository cannot use, is never considered even if its labels match.
- Mixing hosted and self-hosted labels.
runs-on: [ubuntu-latest, self-hosted]matches no runner, because no runner is both.
Designing a label scheme
Labels work best when each one answers a single question. A practical scheme uses three groups:
- Platform:
linux,x64(automatic). - Capability:
gpu,docker,large. - Lifecycle or trust level:
ephemeral,trusted.
Jobs that need only a clean machine ask for ephemeral. Jobs that need a GPU add gpu. Avoid labels that name a specific machine, such as build-host-7. They reintroduce the single reused machine that later chapters argue against.
Exercise
A workflow uses runs-on: [self-hosted, linux, ephemeral]. You have two online runners. Runner 1 has the labels self-hosted, linux, x64. Runner 2 has self-hosted, linux, x64, ephemeral. Which runner can take the job, and why?
Show answer
Runner 2. A job is offered only to runners that carry every label in runs-on. Runner 1 lacks ephemeral, so it is skipped. Runner 2 has all three requested labels, and its extra x64 label does not matter.
Exercise
Your job has been "Queued" for an hour and the runner shows as online. Name two checks you would make.
Show answer
Compare the labels in runs-on with the runner's labels, looking for a typo or missing label. Then confirm that the repository can reach the runner: it must be registered at a scope or in a runner group that includes this repository.