Controller and agent architecture
Why the controller has no executors, and what a build can reach on an agent.
cd ~/lab && curl -fsSLO https://secopslog.com/lab-files/ci-jenkins/arch.tar.gz && tar -xzf arch.tar.gz, which creates ~/lab/arch/. SHA-256: b1b4a99ab17cf7855b5bb350ee5aa2f5d20cceb513684473efac2578d94e529aA pull request adds one line to a build script: cat /var/jenkins_home/secrets/master.key. If that build runs on the Jenkins controller, the line works, and so does anything else an attacker cares to add. Every credential Jenkins stores, every job configuration and every other team's secrets sit on that machine, readable by the account the build runs as.
That's why Jenkins splits into a controller and agents, and why the controller in this lab runs no builds at all. You'll prove it here by trying.
Two roles
An executor is a slot for one piece of work on a node. The number of executors on a node is how many things it does at once. Set the controller's number to zero and it can't run a build step such as sh, whatever a Jenkinsfile asks for. That's the first line of the lab's configuration: numExecutors: 0.
One thing still runs on the controller in every pipeline: the pipeline's own Groovy code. The controller interprets the Jenkinsfile for the whole run, in a lightweight executor that doesn't count against numExecutors, and sends each step to an agent. So the Groovy sandbox, which a later lesson covers, is what limits that code, and heavy logic in script {} blocks costs controller CPU and memory.
A controller alone does no work
Start the lab without its agent and ask Jenkins what nodes it has:
The controller appears as Built-In Node with no executors. The agent is defined but offline. Two jobs now exist: where runs on any node labelled linux, and on-controller asks for the controller by its label, built-in. Run the first one with a 15-second limit:
Jenkins accepted the build and started it, and then nothing happened. The pipeline's Groovy started on the controller, and it waits for a real executor when it reaches agent. The waiting: line is the queue's own explanation. Exit status 3 is how our script reports that it gave up waiting. On a real server, a build that sits like this usually means a label with no matching online agent, so the queue reason is the first thing to read.
Agents have to prove who they are
An agent connects with a name and a secret that the controller generated for that name. Try connecting with a made-up secret:
The controller refused the connection with Authorization failure, and the agent kept trying again, as the count shows. The secret matters because a machine that connects as your agent receives build steps, including whatever credentials those steps use. Now connect the real agent. agent.sh fetches the correct secret through the authenticated API:
Our script stopped build 1 when it gave up waiting, so this is build 2, and this one ran. hostname is the agent container's ID, the account is jenkins, and the workspace is under /home/jenkins/agent. Most importantly, /var/jenkins_home doesn't exist there. A build step on this agent can't read the controller's files, because they're on a different machine.
What the separation protects
Here's what a build would have reached on the controller:
hudson.util.Secret is one of the keys that decrypts stored credentials. Now try to run the second job, which asks for the controller directly:
It waits, and goes on waiting, even with a healthy agent online, because the only node with the label built-in has no executors. Keeping numExecutors: 0 turns "don't build on the controller" from a rule people must remember into something Jenkins enforces. Clean up with ./down.sh.
Hands-on
In a fresh lab (./up.sh, ./seed.sh app app/, then ./newjob.sh where app), edit casc.d/00-base.yaml so the agent has labelString: linux fast, then run docker compose --progress quiet up -d --force-recreate --wait controller (this recreates Jenkins with the new configuration; the next lesson explains it) and ./agent.sh. Change app/Jenkinsfile to request label 'gpu', push it with ./commit.sh, and run it with BUILD_WAIT=15 ./run-job.sh where. Read the waiting: line, then change the label to fast and run it again. Finish with ./down.sh.
What you should see: with gpu the build starts and then waits, and the queue explains why: There are no nodes with the label ‘gpu’. run-job.sh stops it after 15 seconds and exits 3. After the change to fast, the next build runs on lab-agent and finishes SUCCESS, because the agent now carries both labels.
Remember
The on-controller job could wait forever and never read secrets/, because the controller has no executors to give it. When a build sits still with no error, read the queue reason first.
Started by user admin and then nothing for ten minutes. CPU on the controller is idle. What do you check first?/queue says why, usually a label with no online agent.numExecutors: 0 on the controller. A Jenkinsfile then uses agent { label 'built-in' }. What happens?