Since module 1, every TecnoShop build has run on the built-in node, inside the same container as the controller. We have flagged this as temporary in every module, and now it is time to fix it. In this module Laura takes on her role as Jenkins administrator, and her first task is to separate whoever orchestrates (the controller) from whoever builds (the agents). In this lesson you will create the permanent agent linux-agent-01 from Manage Jenkins → Nodes, connect it as one more service in the docker-compose.yml of ~/tecnoshop-jenkins, set the built-in node to 0 executors and adapt the orders-api and catalog-web Jenkinsfiles so that they request an agent with the linux label. You will also learn to keep an eye on node status, to disconnect nodes safely and to diagnose a failing connection.
Why Separate the Controller and the Agents
You already know the theory from Jenkins Architecture. From an administrator's point of view, these are the concrete reasons:
| Problem with building on the controller | What happens in practice |
|---|---|
| Security | The build runs as the same system user as Jenkins and can read JENKINS_HOME: secrets/, credentials.xml, the configuration of every job. A sh 'cat ...' in a PR would be enough |
| Stability | A build that runs out of memory or disk also takes down the interface, the queue and every other build |
| Performance | Maven, npm and the Smoke stage compete with Jenkins itself for CPU |
| Restarts | Restarting the controller container kills the processes of any builds in progress (you saw this in 02-05) |
| Tools | Every tool a build needs ends up installed on the controller machine |
The rule TecnoShop will adopt: the controller does not run builds. It only schedules, coordinates, stores the history and serves the interface.
The Manage Jenkins → Nodes Page
Manage Jenkins → Nodes shows a table with every node. Right now there is only one, Built-In Node. The columns are those of the node monitors, which you will see later: architecture, clock difference, free disk space, free swap space, free space in the temporary directory and response time.
From this page you can:
- Create a node with New Node.
- Open a node (click its name) to see its status, its log, its builds and its configuration (Configure).
- Adjust the monitors with Configure Monitors (in some versions it appears as Node Monitoring).
Creating the Permanent Agent linux-agent-01
- Manage Jenkins → Nodes → New Node.
- Node name:
linux-agent-01. Type: Permanent Agent. Create. - Fill in the form:
| Field | Value | Explanation |
|---|---|---|
| Description | General-purpose Linux agent (Docker, JDK 21) |
Free text shown in the node list |
| Number of executors | 2 |
How many builds (or branches with their own agent) it can run at the same time |
| Remote root directory | /home/jenkins/agent |
Directory on the agent where Jenkins stores workspaces, tools and working files |
| Labels | linux |
Labels that jobs will use to request this node. Separated by spaces |
| Usage | Use this node as much as possible |
See the next table |
| Launch method | Launch agent by connecting it to the controller |
The agent initiates the connection (inbound) |
| Availability | Keep this agent online as much as possible |
Jenkins tries to keep it available at all times |
Number of Executors
Each executor is a "slot" for one build. A rule of thumb is one executor per CPU core available to the agent, as long as there is enough memory: every orders-api build starts at least one Maven JVM and, in Smoke, another one with the application. On your laptop, with the controller and the agent on the same machine, 2 is a prudent value. More executors do not mean more speed if the machine cannot cope with all of them.
Remote Root Directory
This is the directory inside the agent where Jenkins does its work. Inside it you will find:
workspace/: one workspace per job (and per branch, in multibranch).tools/: the tools Jenkins installs automatically on the agent, such as Node.remoting/: internal files for the connection (class caches and logs).
The agent image we are going to use already works in /home/jenkins/agent, so it makes sense for the two to match.
Usage: Two Modes
| Mode | Which builds it accepts | When to use it |
|---|---|---|
| Use this node as much as possible | Those that request a label the node has and those that do not request any (agent any, unrestricted freestyle jobs) |
General-purpose agents |
| Only build jobs with label expressions matching this node | Only those that request a label expression matching the node | Special agents: with specific hardware, with access to production, Windows... |
TecnoShop chooses Use this node as much as possible because linux-agent-01 is its general-purpose agent: that way, legacy jobs that do not request a label (orders-api-build, orders-api-smoke, orders-api-regression, lab-credentials) keep working while they are reviewed. Even so, the Jenkinsfiles will always request label 'linux': when agents of other kinds arrive, no Java build will accidentally end up on a machine without the right tools.
Availability
| Option | Behavior |
|---|---|
| Keep this agent online as much as possible | Jenkins tries to keep it connected (with SSH agents, it reconnects them itself) |
| Bring this agent online according to a schedule | Available only during the time windows you specify with cron syntax |
| Bring this agent online when in demand, and take offline when idle | It connects when there is work in the queue and disconnects after a period of inactivity |
The last two make sense with agents that Jenkins can start on its own (SSH). With an inbound agent, which connects on its own initiative, the first one is the usual choice.
- Expand the advanced options of the launch method and check Use WebSocket (we explain it in the next section). Leave Disable WorkDir unchecked.
- Save.
The node appears in the list with a red cross: it has been created, but it is disconnected. Open it: Jenkins shows the instructions for connecting it, with a command similar to this one:
java -jar agent.jar -url http://localhost:8080/ -secret 3f9c...fake... -name "linux-agent-01" -webSocket -workDir "/home/jenkins/agent"
-url: the controller URL.-secret: the node's secret, a hexadecimal string that the agent presents to prove it is who it claims to be. Treat it like a password: anyone who has it can connect on behalf oflinux-agent-01and receive builds, along with the code and secrets they use.-name: the node name, which must match exactly.-webSocket: connect through the HTTP port instead of TCP port 50000.-workDir: the working directory.
You are not going to run that command by hand: the official agent image does it for you using environment variables.
Two Ways to Connect the Agent: Inbound and SSH
| Aspect | (a) Inbound agent (jenkins/inbound-agent) |
(b) SSH agent (SSH Build Agents plugin, jenkins/ssh-agent) |
|---|---|---|
| Who initiates the connection | The agent | The controller |
| What the agent needs | To reach the Jenkins URL | An SSH server and Java |
| What the controller needs | Nothing special (with WebSocket, only its HTTP port) | An SSH credential and network access to port 22 on the agent |
| Authentication | Node secret | SSH key + verification of the host key |
| Startup and reconnection | Handled by the agent process (or by Docker with restart) |
Handled by Jenkins: it can start the agent on demand |
| Agent behind a firewall or NAT | Works (it connects out to the controller) | Difficult: the controller must be able to get in |
| Additional plugin | No | Yes: SSH Build Agents (ssh-slaves) |
| TecnoShop's choice | Yes | Documented alternative |
TecnoShop chooses (a): in Docker Compose it is the simplest approach (there are no SSH keys to manage), the agent reconnects by itself and, with WebSocket, all the traffic goes through port 8080, the same one the HTTPS reverse proxy from 05-02 will use.
WebSocket or Port 50000
| TCP port 50000 | WebSocket | |
|---|---|---|
| Port | An additional one, which has to be published and opened in firewalls | The web interface port (8080, or 443 behind a proxy) |
| HTTP proxies | Cannot pass through them | Pass through them if they allow WebSocket |
| Image variable | (none; it is the default mode) | JENKINS_WEB_SOCKET=true |
TecnoShop uses WebSocket. Port 50000 is no longer needed for this agent; closing it is part of the hardening in 05-02.
Hands-On: the Inbound Agent in docker-compose.yml
Keeping the Secret Out of Git
Copy the secret shown on the node page and save it in a .env file in ~/tecnoshop-jenkins, next to docker-compose.yml. Docker Compose reads that file automatically and substitutes the ${...} variables:
cd ~/tecnoshop-jenkins
cat > .env <<'EOF'
# Secret of the linux-agent-01 node (Manage Jenkins → Nodes → linux-agent-01)
LINUX_AGENT_01_SECRET=paste-the-node-secret-here-0000fake
EOF
chmod 600 .env
echo ".env" >> .gitignorecat > .env <<'EOF' ... EOF: writes the block of text to the file. The quotes around'EOF'stop the shell from interpreting anything inside it.chmod 600 .env: only your user can read and write it.echo ".env" >> .gitignore: if you keep~/tecnoshop-jenkinsunder Git, the secret will never be pushed.
Replace the fake value with the real secret of your node.
The New Service
Edit docker-compose.yml so that it looks like this:
services:
jenkins-controller:
image: jenkins/jenkins:lts-jdk21
container_name: jenkins-controller
restart: unless-stopped
ports:
- "8080:8080"
- "50000:50000" # The agent uses WebSocket; this port is closed in 05-02
volumes:
- jenkins_home:/var/jenkins_home
linux-agent-01:
image: jenkins/inbound-agent:latest-jdk21
container_name: linux-agent-01
restart: unless-stopped
depends_on:
- jenkins-controller
environment:
JENKINS_URL: http://jenkins-controller:8080/
JENKINS_AGENT_NAME: linux-agent-01
JENKINS_SECRET: ${LINUX_AGENT_01_SECRET}
JENKINS_WEB_SOCKET: "true"
JENKINS_AGENT_WORKDIR: /home/jenkins/agent
volumes:
- linux_agent_01:/home/jenkins/agent
volumes:
jenkins_home:
name: jenkins_home
linux_agent_01:
name: linux_agent_01The new service, line by line:
image: jenkins/inbound-agent:latest-jdk21: the official Debian-based inbound agent image, with Java 21 (the same versionorders-apineeds), Git and the connection process (agent.jar). In production you would pin a specific tag, just as you will do with the controller in 05-04.container_name: linux-agent-01: the same name as the node, to avoid confusion.restart: unless-stopped: if the container or the connection goes down, Docker starts it again.depends_on: Compose starts the controller first. Be careful: it only waits for the container to start, not for Jenkins to be ready; if the agent tries to connect too early, it will fail andrestartwill try again.JENKINS_URL: http://jenkins-controller:8080/: the controller URL as seen from the agent. Inside the Compose network, every service resolves by its name. Do not usehttp://localhost:8080/: inside the agent container,localhostis the agent itself.JENKINS_AGENT_NAME: the node name, identical to the one in Jenkins.JENKINS_SECRET: ${LINUX_AGENT_01_SECRET}: the value is taken from.env.JENKINS_WEB_SOCKET: "true": connects over WebSocket through port 8080. The quotes stop YAML from turning it into a boolean.JENKINS_AGENT_WORKDIR: the working directory, the same as the Remote root directory.linux_agent_01:/home/jenkins/agent: a named volume for the working directory. That way, if you recreate the container (for example, when you update the image), the workspaces and the downloaded tools, such as Node, are preserved.- The agent does not publish any ports: there is no need, because it is the agent that connects out to the controller.
Starting and Checking It
docker compose up -d: creates the new container; the controller, which has not changed, keeps running.docker compose logs -f linux-agent-01: follows the agent's log. Look for lines like these:
INFO: Using /home/jenkins/agent/remoting as a remoting work directory INFO: Locating server among [http://jenkins-controller:8080/] INFO: WebSocket connection open INFO: Connected
In the interface, the red cross on linux-agent-01 disappears and its page says Agent is connected. On the Dashboard, Build Executor Status now shows the node with its two idle executors.
Alternative: an SSH Agent with SSH Build Agents
If your organization prefers the controller to open the connection (for example, because the agents are existing servers), the procedure is:
- Install the SSH Build Agents plugin (
ssh-slaves) if you do not have it. - Generate a key pair for the agent, on your machine:
- Create an SSH Username with private key credential (scope System, because only Jenkins uses it to connect), user
jenkins, with the contents ofagent-ssh-key(the private key). For example, with the IDssh-agents. - Add the agent to Compose with the public key:
ssh-agent-01:
image: jenkins/ssh-agent:latest-jdk21
container_name: ssh-agent-01
restart: unless-stopped
environment:
JENKINS_AGENT_SSH_PUBKEY: "ssh-ed25519 AAAAC3...fake... jenkins-agents"- On the node, Launch method: Launch agents via SSH, Host:
ssh-agent-01, Credentials:ssh-agents, Remote root directory:/home/jenkins/agent. - Host Key Verification Strategy: how the controller checks that it is talking to the right agent and not to an impostor.
| Strategy | What it does | Assessment |
|---|---|---|
| Known hosts file Verification Strategy | Checks against ~/.ssh/known_hosts of the controller's user |
Secure; requires preparing that file |
| Manually provided key Verification Strategy | You paste the host's public key into Jenkins | Secure and explicit: the recommended one |
| Manually trusted key Verification Strategy | Trusts the first key it sees (optionally requiring manual approval) | Acceptable if you check manual approval |
| Non verifying Verification Strategy | Checks nothing | Vulnerable to man-in-the-middle attacks: only for throwaway tests |
If the controller cannot find Java on the SSH agent, specify its path in the advanced options (JavaPath); in this image it is /opt/java/openjdk/bin/java.
TecnoShop does not adopt this agent; if you try it as an exercise, remove it afterward.
Checking the Agent's Tools
A build can only use what the agent has. Check from the outside:
docker compose exec linux-agent-01 java -version
docker compose exec linux-agent-01 git --version
docker compose exec linux-agent-01 curl --version
docker compose exec linux-agent-01 whoamijava -version: it must be 21. Both the agent process and theorders-api./mvnwuse it.git --version: the checkout needs it, and the checkout now happens on the agent.curl --version: theSmokestage (smokeSpringBoot) uses it.whoami:jenkins, a user without administrative privileges.
Do not install Node or Maven in the image:
- Maven comes with the
./mvnwwrapper, which downloads it on the first build. - Node is installed by the NodeJS plugin you configured in 04-02: the first time a build requests
node-22on this agent, the plugin will download it to/home/jenkins/agent/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/node-22. There is no need to touch the Tools configuration.
To check it from Jenkins, create a practice Pipeline job called verify-linux-agent with this script:
pipeline {
agent {
label 'linux'
}
stages {
stage('Inspect agent') {
steps {
sh '''
echo "Node: $NODE_NAME | Labels: $NODE_LABELS | Executor: $EXECUTOR_NUMBER"
echo "Workspace: $WORKSPACE"
hostname
whoami
java -version
git --version
'''
nodejs(nodeJSInstallationName: 'node-22') {
sh 'node --version'
}
}
}
}
}agent { label 'linux' }: requests a node with thelinuxlabel.NODE_NAMEandNODE_LABELS: in 04-03 they werebuilt-in; now they should showlinux-agent-01andlinux.WORKSPACE:/home/jenkins/agent/workspace/verify-linux-agent.- The
nodejsblock triggers the download of Node onto the agent the first time.
The Built-In Node at 0 Executors
With the agent up and running, Laura closes the controller's door:
- Manage Jenkins → Nodes → Built-In Node → Configure.
- Number of executors:
0. - Save.
The built-in node still exists (it is the controller itself), but it can no longer run builds. Consequences:
- Security: no build can read
JENKINS_HOMEor the files insecrets/. A maliciousJenkinsfilein a PR would only see the agent's workspace. The protection between agent and controller is completed in 05-02. - The warning goes away: the header warning you saw in 02-01, which told you that builds were running on the built-in node, is no longer shown.
- Pipelines still need the controller: the
Jenkinsfile's Groovy, the loading oftecnoshop-liband the lightweight checkout of theJenkinsfilerun on the controller in a lightweight (flyweight) executor, which does not count toward the configured executors. That is why a pipeline works even though the controller has 0 executors. - Legacy jobs: with the agent in as much as possible mode, the freestyle jobs
orders-api-buildandorders-api-smokeand the practice pipelines withagent anynow run onlinux-agent-01. To make this explicit, in the freestyle jobs check Restrict where this project can be run with the expressionlinux(below it, Jenkins confirms Label linux matches 1 node).
Node Properties: Environment Variables and Tool Locations
In a node's Configure page, the Node Properties section lets you adjust that particular node.
Node Environment Variables
There is one loose end: on the controller, the Maven cache lived in /var/jenkins_home/.m2, inside the volume. On the agent, Maven would create it in /home/jenkins/.m2, outside the linux_agent_01 volume, and it would be lost every time the container is recreated. Laura solves it with a node variable:
- Manage Jenkins → Nodes → linux-agent-01 → Configure → Node Properties → Environment variables.
- Add: name
MAVEN_OPTS, value-Dmaven.repo.local=/home/jenkins/agent/.m2/repository. - Save.
MAVEN_OPTS: an environment variable that Maven (also through./mvnw) adds to the JVM it starts.-Dmaven.repo.local=...: moves Maven's local repository to a path inside the volume.- The variable only exists in builds that run on this node; another agent could have a different path without changing any
Jenkinsfile. This is the use case announced in 04-03.
Tool Locations
Tool Locations tells Jenkins that, on this node, a tool configured in Manage Jenkins → Tools is already installed at a specific path, instead of downloading it. For example, if one day the agent image included Node 22 in /usr/local, you could add the node-22 installation with Home /usr/local. We do not need it today: we prefer the NodeJS plugin's automatic installation.
Node Monitors and Thresholds
Jenkins checks every node periodically:
| Monitor | What it measures | What it does by default |
|---|---|---|
| Free Disk Space | Free space in the node's root directory | Below the threshold, it marks the node offline |
| Free Temp Space | Free space in the temporary directory | Same |
| Free Swap Space | Free swap | Informational only |
| Response Time | How long the agent takes to answer a request from the controller | If it fails to respond several times in a row, it marks the node offline |
| Clock Difference | Time difference from the controller | Informational (large differences confuse timeouts and logs) |
| Architecture | Operating system and architecture | Informational |
In Configure Monitors you can adjust the disk thresholds (an error threshold, which takes the node offline, and a warning one) and check Don't mark agents temporarily offline on each monitor so that it only reports.
- A node marked offline by a monitor stops receiving builds until the problem is fixed and it is brought back online.
- In your environment, the agent's disk is the Docker host's disk: if your laptop is short on space, the monitor will catch it before Maven does.
- Leave the thresholds enabled. A node that is offline for a clear reason is far better than builds failing with
No space left on device.
Monitoring the whole installation, with metrics and history, is covered in 05-05.
Taking a Node Offline, Disconnecting It and Reading Its Logs
On the linux-agent-01 page:
| Action | Effect | When |
|---|---|---|
| Mark this node temporarily offline (with a reason) | Stops accepting new builds; those in progress finish | Before maintenance on the agent |
| Bring this node back online | Accepts builds again | After the maintenance |
| Disconnect | Cuts the connection; builds in progress fail | To force a reconnection |
With an inbound agent, Disconnect does not last long: the agent process reconnects by itself. If what you want is to stop it, mark it offline, wait for its builds to finish and stop the container with docker compose stop linux-agent-01.
For diagnosis, you have two logs:
- Log on the node page: the controller side (connection attempts, disconnections, reasons).
docker compose logs linux-agent-01: the agent side.
| Symptom | Likely cause | Solution |
|---|---|---|
Repeated Connection refused in the agent log |
JENKINS_URL points to localhost, or the controller has not started yet |
Use http://jenkins-controller:8080/; wait, or let restart retry |
UnknownHostException: jenkins-controller |
The agent is not on the same Compose network | Define both services in the same docker-compose.yml |
| Connection rejected on authentication | Wrong secret, or JENKINS_AGENT_NAME differs from the node name |
Copy the secret again; check capitalization and hyphens |
is already connected to this controller |
Two processes using the same node name | Stop the duplicate |
The node connects, but builds stay in the queue with There are no nodes with the label 'linux' |
Label misspelled on the node or in the Jenkinsfile |
Labels are case-sensitive |
| The node shows as offline with a disk-related reason | Free Disk Space monitor | Free up space and click Bring this node back online |
Adapting the Jenkinsfiles: agent { label 'linux' }
orders-api
The only change is the global agent declaration. Before:
After:
agent { label 'linux' }: the whole pipeline runs on a node with thelinuxlabel. Today that islinux-agent-01; tomorrow it could be any other agent with that label, without touching theJenkinsfile.- Why
APP_VERSIONstill works: in 04-03 you saw that theshin the globalenvironmentblock needs an agent. With an agent at pipeline level, Jenkins allocates the node and the workspace and does the checkout before evaluatingenvironment, so./mvnw help:evaluatefinds thepom.xml. If you had chosenagent nonewith per-stage agents, the build would fail before the first stage withRequired context class hudson.FilePath is missing, and you would have to switch to option B from 04-03. - Why not
agent none: in 04-07 we recommendedagent nonewith per-stage agents once agents exist. That recommendation makes sense when the stages need different nodes or there are waits that should not hold an executor. Inorders-apievery stage needs the same kind of node, they share the compiledtarget/and there are no manual waits. A global agent is simpler and keepsAPP_VERSIONworking in Restart from Stage. We will revisit this when the CD pipeline in 07-03 adds approvals.
Make the change on a branch, open it as a PR and merge it once it is green, as always. In the console, the start of the build changes:
The first build on the agent takes longer: it downloads Maven through the wrapper and all the dependencies into the new cache.
catalog-web
catalog-web uses a global agent none, with an agent in each matrix cell and in Build. Only those two declarations change:
stage('Tests per Node version') {
matrix {
// ... axes unchanged ...
agent {
label 'linux'
}
// ... stages unchanged ...
}
}
stage('Build') {
agent {
label 'linux'
}
// ... tools, steps and post unchanged ...
}Here a global agent none is the right choice: each cell needs its own workspace (because of npm ci) and the pipeline should not hold an executor while it waits for its cells.
Executors, Parallel Branches and Workspaces on the Agent
With two executors on linux-agent-01, it helps to know what each build takes up:
| Pipeline | Executors it takes up | Workspaces |
|---|---|---|
orders-api (global agent; the Checks branches do not declare an agent) |
1, for the whole build | One: the Tests and Dependency analysis branches share a workspace, as designed in 04-02 |
catalog-web (cells with their own agent) |
Up to 2 at once; the third cell waits in the queue | One per running cell: catalog-web_main and catalog-web_main@2 |
Important details:
- If the
Checksbranches declared their ownagent { label 'linux' }, each one could go to a different workspace (or even to another agent), with its own checkout and without thetarget/fromBuild. In addition, with the pipeline already holding one executor, only one would be left free and the branches would run one at a time. That is why we do not do it. - When
orders-apiandcatalog-webrun at the same time, they compete for the two executors:orders-apitakes one andcatalog-webruns its cells one at a time. It is the same number of executors the built-in node had, now in the right place. - The
Smokestage starts the application on port18090 + EXECUTOR_NUMBER: on the agent, executors 0 and 1 use ports 18090 and 18091, so two simultaneous builds do not collide. - The
@2suffix appears when two builds of the same job coincide on the same node;orders-apiwill not see it because ofdisableConcurrentBuilds(). - Artifacts, stashes and history remain on the controller:
archiveArtifactsandstashcopy from the agent to the controller. The workspace, on the agent, is disposable, andcleanWs()cleans it there.
The Resulting Topology and What Is Left for Later
flowchart LR
U["Team's browser"] -->|"HTTP 8080"| C
subgraph H["Docker host: ~/tecnoshop-jenkins"]
C["jenkins-controller<br/>Built-In Node: 0 executors<br/>volume jenkins_home"]
A["linux-agent-01<br/>label linux, 2 executors<br/>JDK 21, git, curl<br/>volume linux_agent_01"]
A -->|"WebSocket over HTTP 8080<br/>node secret"| C
end
A -->|"checkout"| G["GitHub: tecnoshop/orders-api<br/>tecnoshop/catalog-web"]
C -->|"lightweight checkout<br/>of the Jenkinsfile and tecnoshop-lib"| G
- The controller serves the interface, interprets the pipelines and stores the history and artifacts.
- The agent runs every
sh, downloads the code and the tools and hosts the workspaces. - The connection arrow goes from the agent to the controller: that is why the agent does not publish any ports.
What this lesson deliberately leaves out:
- Windows and macOS agents: they connect the same way (inbound as a system service, or SSH), with their own particularities; they appear alongside container agents in Jenkins with Docker.
- Ephemeral agents in containers and pods: 08-01 and Jenkins and Kubernetes.
- Many agents and capacity: Scaling Jenkins.
- Permissions and global security (who can configure nodes, agent-to-controller protection, port 50000): 05-02.
Common Mistakes and Tips
JENKINS_URL=http://localhost:8080/in the agent container: this is the most frequent mistake. From inside a container,localhostis the container itself.- Setting the built-in node to 0 executors before connecting the agent: every build gets stuck in the queue. Connect and test the agent first; then close the controller.
- Pushing
.envto Git: the node secret grants the ability to receive builds. Check.gitignorebefore the first commit. - Installing tools by hand inside the agent container (
docker exec ... apt-get install): they are lost when the container is recreated and nobody knows they are there. Use Jenkins tools (NodeJS), wrappers (./mvnw) or, later on, custom images. - Labels with machine names (
linux-agent-01) in theJenkinsfiles: this ties the pipeline to a specific node. Request capabilities (linux), not names. - Disconnecting an agent with builds in progress: the builds fail. Mark it offline first and wait.
- Tip: write down the reason when you mark a node offline ("Disk maintenance, Laura, 10:00-10:30"). The rest of the team will see it in the node list.
Exercises
Exercise 1. Follow the whole lesson: create linux-agent-01, connect it with the Compose service, run verify-linux-agent, set the built-in node to 0 executors, add MAVEN_OPTS and adapt the two Jenkinsfiles. What values do NODE_NAME, NODE_LABELS and WORKSPACE show? Where is Maven's local repository now? Check it from the terminal.
Exercise 2. Change the Usage of linux-agent-01 to Only build jobs with label expressions matching this node and run lab-credentials (which uses agent any) and orders-api-build without a label restriction. What happens and why? What are the two ways to fix it? Afterward, put the mode back the way it was.
Exercise 3. Cause and diagnose two connection failures: (a) change one character of the secret in .env and run docker compose up -d linux-agent-01; (b) restore the secret and change JENKINS_URL to http://localhost:8080/. For each case, describe what the container log and the node's Log show, and put everything back the way it was.
Solutions
Solution 1. NODE_NAME is linux-agent-01, NODE_LABELS contains linux (and the node name itself, which Jenkins always adds as an implicit label) and WORKSPACE is /home/jenkins/agent/workspace/verify-linux-agent. After an orders-api build, the cache is in the agent's volume:
docker compose exec linux-agent-01 ls /home/jenkins/agent/.m2/repository
docker compose exec linux-agent-01 ls /home/jenkins/agent/workspaceThe first command lists directories such as org or com; the second, the jobs' workspaces. If .m2/repository does not exist, check the exact name of MAVEN_OPTS in Node Properties (and remember that the variable only affects builds started after you save).
Solution 2. Both builds stay in the queue indefinitely, with a message such as Waiting for next available executor: the controller has 0 executors and the agent only accepts builds that request a label expression matching it. agent any and an unrestricted freestyle job do not request any. Solutions: (1) request the label explicitly (agent { label 'linux' } in the pipeline and Restrict where this project can be run = linux in the freestyle job), or (2) go back to Use this node as much as possible mode. The first is the one you want in the long run: it makes explicit where each job runs.
Solution 3. (a) The container log shows the controller rejecting the connection, and the container restarts in a loop (docker compose ps shows it as Restarting); in the node's Log you will see the rejected attempts or no new connection at all, and the node stays disconnected. (b) The agent log shows Connection refused when it tries to connect to localhost:8080, because nothing inside the container is listening on that port; the node's Log records nothing, because the request never reaches the controller. That difference is a good diagnostic clue: if the controller does not see the attempt, the problem is the network or the URL; if it sees it and rejects it, the problem is the name or the secret.
Conclusion
TecnoShop no longer builds on the controller. You have created the permanent agent linux-agent-01 with the linux label, 2 executors and /home/jenkins/agent as its root directory, you have connected it as an inbound Docker Compose service over WebSocket with its secret kept out of Git, and you know the SSH alternative and why verifying the host key matters. The built-in node has 0 executors, so no build can read JENKINS_HOME; the Maven cache lives in the agent's volume thanks to a node variable; the monitors watch disk and response time, and you know how to mark a node offline and diagnose a connection from both sides. orders-api requests agent { label 'linux' } at pipeline level, which keeps APP_VERSION working, and catalog-web spreads its cells across the agent's two executors. But security is still exactly as the setup wizard left it: any authenticated user can do anything, from reconfiguring this agent to opening the script console, and that stops being acceptable the moment Diego and Marta get their own accounts. Laura's next step is to decide who can do what, in Configuring Security.
