Runners, executors and tags

How a job finds a runner, why a job waits forever, and what concurrency changes.

Beginner13 min · lesson 2 of 17
Lesson files
The scripts, test data and local test servers this lesson uses, exactly as they ran on the lab machine (15 files, 6 KB): runners.tar.gz. The lab VM shares no folders with your computer, so fetch them inside the VM: cd ~/lab && curl -fsSLO https://secopslog.com/lab-files/ci-gitlab/runners.tar.gz && tar -xzf runners.tar.gz, which creates ~/lab/runners/. SHA-256: a4132fa8c0df26af343b482e93df1f094babe1f61319d072a5edac43e81f583a

"The pipeline is stuck" is one of the most common messages in a CI channel, and it usually isn't stuck at all. A job is pending because no runner wants it, or every runner that would take it is busy. Once you know how a job and a runner find each other, you can tell which in a couple of minutes.

What a runner is

GitLab never runs your jobs. It keeps a queue, and runners poll it. A runner is a GitLab Runner process somewhere you control: a VM, a Kubernetes pod, a laptop. Each runner has an executor that decides how a job runs: shell runs it directly on the host, docker starts a container per job, kubernetes starts a pod. This lab's runner uses the Docker executor:

ubuntu@secopslog-cicd:~/lab/runners · GitLab 19.5.3
$ ./up.sh
runner lab-runner: online (tags: lab,docker) GitLab 19.5.3 is up on http://127.0.0.1:8929
$ docker compose exec -T runner cat /etc/gitlab-runner/config.toml | grep -E '^(concurrent|\[\[runners)|^ (name|url|executor)|^ (image|privileged|network_mode|pull_policy|volumes) '
concurrent = 1 [[runners]] name = "lab-runner" url = "http://gitlab:8929" executor = "docker" image = "alpine:3.24.4@sha256:93b41ef40b1677fce8fcc64ff4af09daddfacf5040afde618bc46c1e2d1cc7d4" privileged = false volumes = ["/cache"] network_mode = "lab-gitlab_default" pull_policy = ["if-not-present"]

concurrent = 1 means this runner process takes one job at a time. image is the default when a job names none. privileged = false keeps job containers unprivileged, and network_mode puts them on the lab network so they can reach http://gitlab:8929. runner.sh registered it the current way: it asks GitLab's API to create a runner, which returns a runner authentication token (glrt-...), and gitlab-runner register stores that token in this file. The older flow with a shared registration token is deprecated, so don't build new automation on it. Guard the glrt- token: whoever has it can pose as this runner and receive its jobs, protected ones and their secrets included. Keep config.toml readable only by the runner, and check the runner list for managers you don't recognise.

ubuntu@secopslog-cicd:~/lab/runners · GitLab 19.5.3
$ ./gl.sh '/runners/all?type=instance_type' | jq -r '.[] | "#\(.id) \(.description) \(.runner_type) online=\(.online)"'; ./gl.sh /runners/1 | jq -c '{tag_list, run_untagged, access_level}'
#1 lab-runner instance_type online=true {"tag_list":["lab","docker"],"run_untagged":true,"access_level":"not_protected"}

An instance runner serves every project on this GitLab. Group runners serve the projects in their group and its subgroups, and project runners serve only their own project. tag_list and run_untagged decide which jobs it accepts.

Tags pick the runner

app/.gitlab-ci.yml
# Which runner picks up a job is decided by tags. Two jobs in one stage can run side by side,
# if the runner allows more than one job at a time.
default:
image: secopslog-py:3.15
tags: [docker]
where:
stage: build
script:
- echo "runner=$CI_RUNNER_DESCRIPTION tags=$CI_RUNNER_TAGS"
- echo "container=$(hostname) user=$(id -un) dir=$CI_PROJECT_DIR"
slow-a:
stage: test
script:
- echo "a start $(date +%T)"; sleep 8; echo "a end $(date +%T)"
slow-b:
stage: test
script:
- echo "b start $(date +%T)"; sleep 8; echo "b end $(date +%T)"
gpu:
stage: test
tags: [gpu]
rules:
- if: $WANT_GPU == "yes"
script:
- nvidia-smi

default: tags: [docker] asks every job for a runner that has the docker tag. A runner takes a job only if it has all the tags the job asks for. A job's own tags: replaces the default instead of adding to it, so gpu asks for gpu only. With no stages: list, GitLab's default stages apply: build, test and deploy, plus .pre and .post. And gpu's rules: add it only when the pipeline variable WANT_GPU is yes, which the rules lesson explains in full. Run it:

ubuntu@secopslog-cicd:~/lab/runners · GitLab 19.5.3
$ ./seed.sh app app/
pushed app: 84168cf first commit
$ ./pipeline.sh app/
--- job where (build): success $ echo "runner=$CI_RUNNER_DESCRIPTION tags=$CI_RUNNER_TAGS" runner=lab-runner tags=["lab", "docker"] $ echo "container=$(hostname) user=$(id -un) dir=$CI_PROJECT_DIR" container=runner-ie2pcrtoj-project-1-concurrent-0 user=root dir=/builds/root/app --- job slow-a (test): success $ echo "a start $(date +%T)"; sleep 8; echo "a end $(date +%T)" a start 00:14:03 a end 00:14:11 --- job slow-b (test): success $ echo "b start $(date +%T)"; sleep 8; echo "b end $(date +%T)" b start 00:14:15 b end 00:14:23 pipeline #1: success

The job container ran as root, because that's the image's default user, and the builds directory is /builds/root/app. And slow-b started only after slow-a ended, although they're in the same stage, because the runner takes one job at a time.

A job no runner will take

The gpu job asks for a gpu tag, which no runner has. run-pipeline.sh starts a pipeline through the API with WANT_GPU=yes, so its rule adds the job:

ubuntu@secopslog-cicd:~/lab/runners · GitLab 19.5.3
$ ./run-pipeline.sh app WANT_GPU=yes
pipeline #2 created source=api
$ PIPE_WAIT=40 ./pipeline.sh app/ | grep -E "^(--- job|pipeline)"; exit ${PIPESTATUS[0]}
--- job where (build): success --- job slow-a (test): success --- job slow-b (test): success --- job gpu (test): pending pipeline #2 still running after 40s
$ ./gl.sh '/projects/root%2Fapp/jobs?scope=pending' | jq -r '.[] | "\(.name): \(.status), tags=\(.tag_list | join(",")), runner=\(.runner.description // "none")"'
gpu: pending, tags=gpu, runner=none

Nothing failed, and nothing will. The job sits in pending with no runner, and the pipeline stays running until someone cancels it or a runner with that tag appears. In the UI, GitLab marks such a job as stuck and says no runner matches its tags. When a pipeline seems frozen, compare the job's tags with your runners' tags before you look anywhere else.

Concurrency

Raise concurrent to 2 in the runner's config file. The runner watches the file and reloads it without a restart:

ubuntu@secopslog-cicd:~/lab/runners · GitLab 19.5.3
$ docker compose exec -T runner sed -i 's/^concurrent = 1/concurrent = 2/' /etc/gitlab-runner/config.toml && sleep 5 && docker compose logs --no-log-prefix runner 2>&1 | grep -o 'Configuration loaded.*' | tail -1
Configuration loaded builds=0 max_builds=2
$ for st in running pending; do ./gl.sh "/projects/root%2Fapp/pipelines?status=$st" | jq -r ".[].id"; done | xargs -r -I{} ./gl.sh "/projects/root%2Fapp/pipelines/{}/cancel" -X POST -o /dev/null; ./run-pipeline.sh app >/dev/null; ./pipeline.sh app/ | grep -E "^(--- job|a |b |pipeline)"
--- job where (build): success --- job slow-a (test): success a start 00:15:27 a end 00:15:35 --- job slow-b (test): success b start 00:15:27 b end 00:15:35 pipeline #3: success

The parallel step first cancelled the pipeline with the stuck gpu job, so it no longer holds a slot, and then started a new one. Now both slow jobs started in the same second. Concurrency is capacity on the runner side. Stages and needs only decide what may run, and whether jobs really overlap depends on free slots on runners that accept them. The same applies to a machine: concurrent = 10 on a 2-CPU VM makes ten jobs share two CPUs.

Watch out
Every job on this runner can reach whatever the runner's host can reach, and with the Docker executor the job containers share that host's Docker. One runner for every project is convenient and is also how one project's job ends up next to another project's secrets. The runner isolation lesson splits runners by trust.

Hands-on

Register a second runner that has the gpu tag: ./runner.sh gpu gpu-runner. It is the same lab container with a second [[runners]] entry, so the "GPU" is pretend. Start a pipeline with ./run-pipeline.sh app WANT_GPU=yes, wait for it with ./pipeline.sh app/, and list every gpu job with the runner that took it: ./gl.sh '/projects/root%2Fapp/jobs?per_page=20' | jq -r '.[] | select(.name=="gpu") | "\(.id) \(.status) \(.runner.description)"'. It will fail, because the image has no nvidia-smi, but it will no longer wait. Finish with ./down.sh.

What you should see: gpu-runner came online with the gpu tag, and this time the gpu job was picked up at once by gpu-runner, then failed with nvidia-smi: command not found and exit code 127. Listing the gpu jobs shows both attempts: the new one failed, runner=gpu-runner, and the one from the walkthrough canceled, runner=none, because no runner ever took it. A failure on the right runner is progress: the job no longer waits for a tag nobody has.

Remember

GitLab queues jobs and runners pull them, matched by tags. A pending job with no runner is a tag or capacity problem, not a broken pipeline. concurrent is the runner's job limit, and a stage never runs faster than the runners allow.

Quick check
01A job has tags: [linux, large]. Runner A has tags linux, runner B has linux, large, arm64. Which runner can take it?
Incorrect — A runner needs every tag the job asks for, and A lacks large.
Correct — Extra tags on the runner are fine. Missing ones are not.
Incorrect — Tags are a hard filter. A job never runs on a runner missing one of its tags.
Incorrect — Extra runner tags do not disqualify it.
02Two jobs in the same stage always run one after the other. The runner's host has 8 idle CPUs. What is the likely cause?
Incorrect — Jobs in a stage can run at the same time. Something limits it here.
Incorrect — Caches do not serialize jobs.
Incorrect — It can run many. The limit is configured.
Correct — The lab showed exactly this, and raising it to 2 let both jobs start in the same second.
03A pipeline has shown running for an hour. One job is pending and no runner is assigned. What should you check first?
Correct — A pending job without a runner is almost always a tag mismatch or a busy or offline runner.
Incorrect — A pending job has not started, so its script has not run yet.
Incorrect — That would show up everywhere, not as one pending job.
Incorrect — Pulling happens on a runner after the job is picked up. This job has no runner yet.

Related