# Run on both: switch GitHub Actions runners with a repo variable, roll back in 30 seconds

Source: https://sengi.run/blog/github-actions-runner-rollback

By Sengi · Last checked November 28, 2026

## How do you switch GitHub Actions runners without risking a bad day?

Put the runner label in a repository variable, `runs-on: ${{ vars.CI_RUNNER || 'ubuntu-latest' }}`, and switching becomes a setting instead of a pull request. Setting the variable takes under a second and every new job follows it; jobs already queued keep their old label, and one short `gh` loop cancels and re-runs them on the runner you switched back to. In our test on November 28, 2026, that moved three stuck runs back to `ubuntu-latest` in 12 seconds. Required checks keep their names because the job name never changes. The same pattern works for any provider, including GitHub’s own runners.

**Last checked November 28, 2026**: the variable, comparison and rollback snippets on this page were run on a private test repository that day, against GitHub’s contexts and variables references read the same day.

## What can actually go wrong when you switch

Three things, and each has a different fix:

- **The new runner is missing something your job needs**: a preinstalled tool, more disk, a service container. You find out on the first run. See [what breaks when you move off GitHub-hosted runners](https://sengi.run/questions/what-breaks-moving-off-github-hosted-runners).
- **The new runner is slower or more expensive for one job** than you expected. You find out by running the same job on both, below.
- **The runner you depend on is down**, yours or GitHub’s. Jobs sit at “Waiting for a runner to pick up this job”, and you need everything back on a working runner quickly.

All three are cheap if the runner label lives in one place you can change without a commit. That is the whole trick.

## Pattern 1: the runner is a repository variable

Change each Linux job once:

```
jobs:
  test:
    runs-on: ${{ vars.CI_RUNNER || 'ubuntu-latest' }}
    steps:
      - uses: actions/checkout@v4
      - run: make test
```

Merge that with no variable set and nothing changes: GitHub’s contexts reference says an unset variable reads as an empty string, so the expression falls back to `ubuntu-latest`. We checked: the first run printed an empty value and ran on GitHub’s 2-core runner.

Now switch with one command (it needs the GitHub CLI signed in as someone who can change the repository’s settings):

```
gh variable set CI_RUNNER --body ubuntu-slim -R your-org/your-repo
```

That call took 0.6 seconds in our test, and the next run’s job reported the label `ubuntu-slim` through the jobs API. To switch back, set it to `ubuntu-latest`, or delete it with `gh variable delete CI_RUNNER` and let the fallback take over.

Three details from GitHub’s variables reference, read November 28, 2026:

- **Use a repository or organization variable, not an environment variable.** Environment-level variables “are only available on the runner after the job starts executing”, which is too late to choose the runner.
- **The lowest level wins.** A repository variable overrides an organization variable of the same name, so set `CI_RUNNER` on the organization for everyone and override it on one repository to try something.
- **One variable per kind of job** if your jobs differ. `CI_RUNNER_LINT` and `CI_RUNNER_BUILD` let you move light jobs first and heavy builds later.

For reusable workflows, pass the label as an input from the caller (`runs-on: ${{ inputs.runner }}`) so the choice stays visible in the calling workflow. [Changing the runner without editing every workflow](https://sengi.run/questions/change-runner-without-editing-workflows) covers the one-time edit across many files.

## Pattern 2: run the same job on both runners

Before you move a job, run it on both and compare. A manual workflow with a matrix does it without touching your real CI:

```
name: Compare runners
on:
  workflow_dispatch:
    inputs:
      candidate:
        description: Runner label to try
        required: true
        default: ubuntu-slim
jobs:
  test:
    strategy:
      fail-fast: false
      matrix:
        runner: [ubuntu-latest, "${{ inputs.candidate }}"]
    runs-on: ${{ matrix.runner }}
    name: test (${{ matrix.runner }})
    steps:
      - uses: actions/checkout@v4
      - run: make test
```

Start it with `gh workflow run "Compare runners" -f candidate=<label>`. Our run produced two jobs, `test (ubuntu-latest)` and `test (ubuntu-slim)`, each on its own runner. `fail-fast: false` keeps one runner’s failure from cancelling the other, so you see both results.

Compare more than one run. Then read each job’s start and finish time from the API and price it, rounded up to whole minutes the way GitHub and most providers bill:

```
gh api repos/your-org/your-repo/actions/runs/RUN_ID/jobs \
  -q '.jobs[] | [.name, .started_at, .completed_at] | @tsv'
```

Keep this workflow out of your required checks: the matrix puts the runner in the job name, so the check name changes with the label.

## Pattern 3: move part of the work first

You do not have to move a whole repository at once. Three ways to stage it, all with the same variable:

- **By job.** Point only the lint and unit-test jobs at `vars.CI_RUNNER_LINT`; leave release builds on the label they have.
- **By repository.** Set the variable on one repository, watch a week of runs, then set it on the organization.
- **By branch.** Keep the default branch on the runner you trust while pull requests try the new one:
  ```
  runs-on: ${{ github.ref == 'refs/heads/main' && 'ubuntu-latest' || vars.CI_RUNNER || 'ubuntu-latest' }}
  ```

## Required checks and branch protection

Branch protection matches a required check by its name, and a job’s check is named after the job. With Pattern 1 the job is still called `test` on every runner (our runs on `ubuntu-latest` and `ubuntu-slim` both reported the name `test`), so a required `test` check keeps passing after the switch and after the rollback.

What does break checks is renaming the job while you switch, or adding a matrix: a matrix job is reported as `test (ubuntu-latest)`, and a pull request waiting on `test` waits forever. Change the label, not the name.

## The outage playbook: everything back in under a minute

The `||` fallback does not protect you from an outage. It only applies when the variable is empty. A job whose label no online runner serves waits in the queue, and it keeps the label it was given: in our test, a job queued on a label nobody served still showed that label after we changed the variable.

So a rollback has two halves: point new jobs at the working runner, then cancel and re-run what is already stuck. A re-run evaluates `runs-on` again with the variable’s current value; our cancelled job came back as attempt 2 on `ubuntu-latest` and passed. This script does both halves:

```
REPO=your-org/your-repo
gh variable set CI_RUNNER --body ubuntu-latest -R "$REPO"
gh run list -R "$REPO" --status queued -L 1000 --json databaseId -q '.[].databaseId' > queued-runs.txt
while read -r id; do gh run cancel "$id" -R "$REPO"; done < queued-runs.txt
while read -r id; do
  until [ "$(gh run view "$id" -R "$REPO" --json status -q .status)" = completed ]; do sleep 2; done
  gh run rerun "$id" --failed -R "$REPO"
done < queued-runs.txt
```

We ran it with three runs stuck on an unserved label. It finished in 12 seconds, and all three completed on `ubuntu-latest` as attempt 2. The `until` loop waits for each cancellation to finish before re-running that run, and `-L 1000` lifts `gh run list`’s default of 20 runs. `--failed` re-runs only the cancelled and failed jobs, so finished jobs are not billed twice. It works the same in bash and zsh.

Two limits worth knowing. `--status queued` finds runs where nothing has started; a run with some jobs finished and some waiting shows as in progress, and runs held by a concurrency group or an environment approval show as pending or waiting, so check those in the Actions tab. And if an organization variable is the one you switched, run the loop for each affected repository.

## Checklist

1. Change each Linux job to `runs-on: ${{ vars.CI_RUNNER || 'ubuntu-latest' }}` in one pull request, with no variable set.
2. Add the compare workflow and run it a few times with the new label.
3. Set the variable on one repository, or one kind of job, and watch real runs.
4. Keep job names unchanged so required checks keep matching.
5. Save the rollback script where the on-call person can find it.
6. Move the next repository or job type.

## Trying Sengi this way

Sengi’s labels drop straight into the variable: `sengi-basic-2-ubuntu-2404` is the same 2 vCPU, 8 GB shape as a private repository’s `ubuntu-latest`, at $0.001 a minute against GitHub’s $0.006, and `sengi-basic-4-ubuntu-2404` and `sengi-basic-8-ubuntu-2404` are $0.002 and $0.004. Connect the repository to Sengi, run the compare workflow with `-f candidate=sengi-basic-2-ubuntu-2404`, then set `CI_RUNNER`. The rollback is the same script. New accounts get 3,000 free credits a month, enough for 3,000 Basic minutes at 2 vCPU, with no card. All six labels and sizes are in the [runner sizes docs](https://sengi.run/docs/runner-sizes).

## Frequently asked questions

### Can runs-on read a repository variable?

Yes. GitHub's contexts reference lists github, needs, strategy, matrix, vars and inputs as the contexts available in jobs.<job_id>.runs-on, so runs-on: ${{ vars.CI_RUNNER || 'ubuntu-latest' }} works. An unset variable is an empty string, so the expression falls back to ubuntu-latest.

### How fast is a rollback?

Setting the variable with gh variable set took under a second in our test, and every job queued after that used the old runner. Jobs already queued keep the label they were given; cancelling and re-running them moved three stuck runs back in 12 seconds.

### Does a re-run use the new variable value?

Yes. In our test a run queued on a label with no runner was cancelled, the variable was set back to ubuntu-latest, and the re-run (attempt 2) ran on ubuntu-latest.

### Will my required status checks break?

Not with a variable. The check is named after the job, and the job name stays the same whichever runner the variable picks. A matrix that includes the runner adds it to the name, such as test (ubuntu-latest), so keep matrix comparisons out of required checks.

### Can I use an environment variable in runs-on?

No. GitHub's variables reference says environment-level variables are only available after the job starts, which is after the runner is chosen. Use a repository or organization variable.

### Does GitHub fall back to ubuntu-latest if the other runner is down?

No. The || fallback only covers a variable that is not set. A job whose label no runner serves waits in the queue until you change the label and re-run it.
