Learn › Jenkins

Jenkins Agents: Run Builds on Windows and Linux Machines

Why builds shouldn't run on the Jenkins controller, how to add a Linux agent over SSH and a Windows agent as a service, and how to target them with labels.

Intermediate 11 min read
By Gopinath Karthikeyan

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.

Jenkins controller schedules jobs and agents run them against servers Git repo Jenkinsfile + scripts Git repo Jenkinsfile + scripts You Build with Parameters நீங்கள் Build with Parameters webhook webhook Jenkins controller Schedules jobs · stores results · 0 executors Jenkins controller Jobs schedule · results · 0 executors Windows agent PowerShell · WinRM Windows agent PowerShell · WinRM Linux agent Ansible · SSH · Docker Linux agent Ansible · SSH · Docker Target servers Reached only from agents, with stored credentials Target servers Agents மூலம் மட்டும், stored credentials உடன்
The controller decides what runs and keeps the history; agents with the right tools and network access do the work.Controller எதை இயக்குவது என்று முடிவு செய்து history-ஐ வைத்திருக்கும்; சரியான tools, network உள்ள agents வேலையை செய்யும்.

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:

  1. Install the SSH Build Agents plugin if needed.
  2. Manage Jenkins → Nodes → New Node → Permanent Agent.
  3. Remote root directory /home/jenkins/agent, labels linux ansible.
  4. Launch method Launch agents via SSH, host, and an SSH Username with private key credential.
  5. 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):

  1. New Node → Permanent Agent, remote root D:\JenkinsAgent, labels windows.
  2. Launch method Launch agent by connecting it to the controller. Tick Use WebSocket to need only the normal HTTPS port.
  3. Save – Jenkins shows a command with agent.jar, the controller URL and a secret.
  4. On the Windows server, install Java 21, download agent.jar from the URL shown, and test the command in a PowerShell window.
  5. Run it permanently as a Windows service under a dedicated service account (tools like WinSW wrap agent.jar as 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() in post { always { } } (Workspace Cleanup plugin) or use options { 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 questions

JenkinsAgentsWindowsLinuxIntermediate

Gopinath Karthikeyan

Gopinath Karthikeyan – Windows Site Reliability Engineer with about 12 years in enterprise Windows Server infrastructure, and founder of WinOps Academy. YouTube · LinkedIn

More in Jenkins