Sub topic 4
Sending jobs to the right runner with labels
This chapter explains how runs-on matches a job to a runner. It covers the default labels, custom labels, matching rules, and the failures that come from mismatched labels. It assumes you can read basic workflow syntax (on, jobs, steps, runs-on), are comfortable in a Linux shell, and know what it means to register a runner.
What a label is
A label is a plain text tag attached to a registered 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.
Labels do not carry meaning on their own. GitHub does not check that a runner labeled gpu has a GPU, or that one labeled ephemeral is ephemeral. The label is a promise made by whoever configured the runner. Treat labels as a routing contract that your team keeps accurate.
Default labels
When you register a self-hosted runner, GitHub adds labels automatically:
| Label | Meaning |
|---|---|
| `self-hosted` | The runner is not GitHub-hosted. |
| `linux`, `windows`, or `macOS` | The operating system of the host. |
| `x64`, `arm`, or `arm64` | The CPU architecture of the host. |
These come from the runner application, based on the machine it runs on. You cannot remove them. Because every self-hosted runner has them, a job that lists only self-hosted can land on any self-hosted runner you own that is visible to the repository.
Custom labels
You add custom labels at registration time with --labels. They are free-form strings, separated by commas. The registration command from the earlier chapters already does this:
./config.sh \
--url https://github.com/OWNER/REPO \
--token REGISTRATION_TOKEN \
--name "runner-$(hostname)-$(date +%s)" \
--labels ephemeral \
--ephemeral \
--unattended
./run.shHere the runner ends up with five labels: self-hosted, linux, x64 (assuming a Linux x64 host), and the custom label ephemeral. The --ephemeral flag is a separate option. It makes the runner take one job and remove itself. It does not add a label. Adding the ephemeral label is your own convention, and the flag and the label are independent.
You can also manage labels after registration, in the runner's settings page or through the REST API. Changing labels on a live runner is possible, but for ephemeral fleets it is better to set labels once, in the image or launch template that creates each runner.
How matching works
A job's runs-on value can be a single string or a list:
name: test
on: pull_request
permissions:
contents: read
jobs:
test:
runs-on: [self-hosted, linux, x64, ephemeral]
steps:
- uses: actions/checkout@v4
- run: make testThe rule is an AND, not an OR. A runner is eligible only if it has all four labels. A runner with self-hosted, linux, and x64 but no ephemeral label is skipped. Extra labels on the runner are fine. A runner with a fifth label gpu still matches this job.
flowchart TDThe diagram below shows the decision a job goes through.
Three conditions must all hold: label match, visibility, and availability. Labels cover only the first. The next chapters cover visibility through runner groups. A job that matches by label but cannot see the runner behaves exactly like one with no match.
Hosted labels and self-hosted labels together
GitHub-hosted runners are also selected by label, such as ubuntu-latest. The two worlds do not mix in one list. If you write runs-on: [ubuntu-latest, self-hosted], no runner has both, so the job never starts. Use one or the other.
jobs:
lint:
runs-on: ubuntu-latest # GitHub-hosted
build:
runs-on: [self-hosted, linux] # your own runnerEach job in a workflow chooses its own runner, so one workflow can use both. This is a good pattern when only some jobs need private network access or special hardware. Run lint and unit tests on hosted runners and send only the deployment job to your fleet.
Designing a label scheme
Labels are cheap, so teams tend to invent too many. A scheme that stays maintainable usually has a few dimensions:
- Platform: the defaults (
linux,x64). Do not repeat them. - Capability: what the machine has, such as
gpu,docker, orlarge(more CPU and memory). - Environment or network zone: where it can reach, such as
prod-networkorstaging. - Lifecycle: how it is created, such as
ephemeral.
Keep these rules in mind:
- Name the capability, not the machine.
gpuis useful.build-server-7ties workflows to one host, which breaks as soon as the fleet autoscales. - Keep the set small and documented. Each new label splits your pool, and a rarely used combination can have zero available runners.
- Use the lifecycle label as a guard. If every ephemeral runner carries
ephemeraland no persistent runner does, then jobs that requireephemeralcan never run on a reused machine. That makes the label a cheap but real safety check.
Point 3 is only as strong as your discipline. A persistent runner that someone registers with --labels ephemeral will attract those jobs. Pair the label with controls that do not depend on honesty: runner groups, covered later in this tutorial, and automation that is the only thing allowed to register runners.
Labels are not a security boundary
It is easy to read a label as a gate. It is not one. Labels decide where a job is sent. They do not decide who may send it.
- Anyone who can edit a workflow file and run it can write any
runs-onlist they like. If the runner is visible to their repository, a matching label is all they need. - A label cannot stop a job from landing on a runner that has been used before, unless the runner's lifecycle enforces that.
- A runner can carry a label placed by anyone with permission to administer it.
Access control comes from runner groups and from restricting which repositories and workflows may use a group. Labels sit on top of that, for convenience and routing. If you remember one thing, remember this: use labels to choose among runners the job is already allowed to use.
Registration scope and label visibility
Where you register a runner affects who can match it. A runner registered to a single repository is visible only to that repository. A runner registered at the organization level sits in a runner group, and the group sets which repositories can use it. An enterprise-level runner works the same way across organizations.
So the same runs-on list can behave differently in two repositories. In one repository the job finds the runner and starts. In the other, the label matches a runner that exists but is not visible, and the job waits. When debugging, check scope and group membership as well as spelling.
Labels with just-in-time runners
Ephemeral runners created through the API need their labels fixed at creation time. The just-in-time endpoint takes a labels list in the request, and the runner starts with exactly those labels:
gh api --method POST /repos/OWNER/REPO/actions/runners/generate-jitconfig \
-f name="jit-runner-1" \
-F runner_group_id=1 \
-f 'labels[]=self-hosted' \
-f 'labels[]=linux' \
-f 'labels[]=x64' \
-f 'labels[]=ephemeral' \
--jq .encoded_jit_config > jitconfig.txt
./run.sh --jitconfig "$(cat jitconfig.txt)"Two details matter here. First, you pass the full label list yourself, including self-hosted, the operating system, and the architecture. The API requires that you supply labels, and a runner created without the labels your workflows ask for will never be picked. Second, the label list is part of a single-use registration. There is no later chance to fix a typo on that runner, because it takes one job and is gone. If the labels are wrong, the job that needed it stays queued, and the orphaned runner sits idle until you remove it.
Common errors
| Symptom | Likely cause | What to check |
|---|---|---|
| Job stays "Queued" or "Waiting for a runner" | No online runner has all listed labels. | Compare `runs-on` against the runner's labels, character by character. |
| Job queued, runner shows Idle | Runner is not visible to the repository. | Runner group access and repository scope. |
| Job queued after a fleet scale-down | All matching runners were used and removed, and no new one was created. | Autoscaler logs and label settings on new runners. |
| Job runs on an unexpected machine | `runs-on` is too loose, such as only `[self-hosted]`. | Add capability and lifecycle labels. |
| Job never starts with `[ubuntu-latest, self-hosted]` | Hosted and self-hosted labels were mixed. | Use one runner type per job. |
| Job fails with "No runner matching the specified labels was found" | Label typo or missing label. | Spelling and case in `runs-on`. |
A queued job waits for a long time before GitHub gives up on it, so a label mistake can look like a slow queue. If a job has been queued longer than your fleet normally takes to start a runner, suspect labels before capacity.
A short debugging routine
- Open the queued job and copy its
runs-onlabels. - List runners in the repository or organization settings and read the labels on each.
- Confirm at least one runner has every label and shows Online.
- Confirm that runner's group lists this repository.
- If the runner is Active, it is busy. The job is waiting for it to finish, which is normal.
You can also list runners from the command line:
gh api /repos/OWNER/REPO/actions/runners \
--jq '.runners[] | {name, status, busy, labels: [.labels[].name]}'The output shows each runner's name, whether it is online, whether it is busy, and its label names. This is quicker than the web page when you have dozens of runners.
Exercise
A workflow uses runs-on: [self-hosted, linux, x64, ephemeral]. Your only matching runner has the labels self-hosted, linux, x64, and gpu, and it is online and idle. The job stays queued. Why, and how would you fix it?
Show answer
The runner lacks the ephemeral label, and all listed labels must be present. Either register a runner that carries ephemeral (and is actually ephemeral, for example with --ephemeral), or change the job's labels if the persistent runner is truly acceptable. Extra labels such as gpu on the runner do not matter. The fix that keeps the safety intent is to create an ephemeral runner with the full label set.
Exercise
A teammate proposes that the ephemeral label alone keeps sensitive jobs off reused machines. Give two reasons this is not enough.
Show answer
First, a label is only a claim. Anyone who can register a runner can attach ephemeral to a persistent one, and the system does not verify it. Second, labels route jobs but do not restrict who may submit them. Any workflow in a repository that can see the runner can request the label. Runner groups, repository and workflow restrictions, and automated registration are needed to enforce the rule.