In the beginner guides, Jenkins ran everything on its own server (the controller). That’s fine for a lab. In real use, builds run on agents – separate machines that do the work while the controller only schedules and stores results.
Why use agents
- Security – a build can run any command. On the controller it could read every stored credential and job config.
- The right tools – Windows tasks (PowerShell 5.1 modules, RSAT, .NET builds) need a Windows agent; Ansible needs Linux.
- Capacity and network reach – put an agent close to the servers it manages, e.g. one per data centre or cloud region.
Once you have agents, set the controller’s Number of executors to 0 (Manage Jenkins → Nodes → Built-In Node → Configure) so nothing runs there.
Labels
Each agent gets one or more labels such as linux, ansible, windows, dc-east. Pipelines ask for labels, not machine names:
pipeline {
agent { label 'linux && ansible' }
stages {
stage('Run playbook') { steps { sh 'ansible --version' } }
}
}
Different stages can use different agents:
pipeline {
agent none
stages {
stage('Lint') {
agent { label 'windows' }
steps { powershell 'Invoke-ScriptAnalyzer -Path scripts -Recurse' }
}
stage('Deploy') {
agent { label 'linux && ansible' }
steps { sh 'cd ansible && ansible-playbook site.yml' }
}
}
}
Add a Linux agent over SSH
On the agent machine:
sudo apt install -y openjdk-21-jre # same Java major version as the controller
sudo adduser --disabled-password jenkins
sudo -u jenkins mkdir -p /home/jenkins/agent
Add the controller’s public key (from a dedicated key pair) to /home/jenkins/.ssh/authorized_keys.
In Jenkins:
- Install the SSH Build Agents plugin if needed.
- Manage Jenkins → Nodes → New Node → Permanent Agent.
- Remote root directory
/home/jenkins/agent, labelslinux ansible. - Launch method Launch agents via SSH, host, and an SSH Username with private key credential.
- Host Key Verification Strategy: Known hosts file or Manually trusted – avoid “Non verifying” outside a lab.
Add a Windows agent
Windows agents usually connect to the controller (an inbound agent):
- New Node → Permanent Agent, remote root
D:\JenkinsAgent, labelswindows. - Launch method Launch agent by connecting it to the controller. Tick Use WebSocket to need only the normal HTTPS port.
- Save – Jenkins shows a command with
agent.jar, the controller URL and a secret. - On the Windows server, install Java 21, download
agent.jarfrom the URL shown, and test the command in a PowerShell window. - Run it permanently as a Windows service under a dedicated service account (tools like WinSW wrap
agent.jaras a service), so it survives reboots and logoffs.
Treat the agent secret like a password – anyone with it can connect as that agent.
Use the right step on each OS
| Step | Runs on |
|---|---|
sh '...' |
Linux / macOS agents |
bat '...' |
Windows (cmd) |
powershell '...' |
Windows PowerShell 5.1 |
pwsh '...' |
PowerShell 7 (any OS) |
Keep agents healthy
- Patch agents like any server – they hold credentials during builds.
- Clean workspaces: add
cleanWs()inpost { always { } }(Workspace Cleanup plugin) or useoptions { skipDefaultCheckout() }where suitable. - Watch disk space – a full agent disk is a classic cause of mysterious build failures.
FAQ
Why does my job wait with “There are no nodes with the label…”? No online agent has that label combination. Check spelling, agent status, and whether all its executors are busy.
What’s next
Next: Jenkins shared libraries and approval gates.
Practise this topic
Test yourself with free questions on this topic – instant answers and explanations.
Start practice questionsJenkinsAgentsWindowsLinuxIntermediate