Why Master-Slave?
Jenkins uses a Master-Slave (Master-Agent) architecture to manage distributed builds. The Master is the main Jenkins server; Slaves are additional servers/agents that share the workload. Master and Slave nodes communicate over the TCP/IP protocol.
- Using slaves, jobs get distributed and the load on the master reduces — Jenkins can run more builds concurrently.
- Allows different environments to be set up on different slaves (Java, .NET, Terraform, etc.).
- Supported slave types: Linux, Windows, Docker, Kubernetes, ECS (AWS).
- If no slaves exist, the master does all the work by default.
Setting Up Master & Slave
- Launch 3 EC2 instances with the same key-pair (name them master, slave-1, slave-2 for clarity).
- Install Jenkins on the master server, and only Java on the slave servers — using the same Java version as the master.
- On the master: Manage Jenkins → Nodes & Clouds → New Node.
- Give the node a name and select Permanent Agent → Create.
New Node Configuration Fields
- Number of executors — default is 2, maximum 5. More executors = faster/parallel builds.
- Remote root directory — the slave server path where Jenkins info is stored (e.g.
/home/ec2-user).
- Labels — a way to tag/name one or more slaves (e.g. "dev", "prod", "linux", "docker").
- Usage — select "Only build jobs with label expressions matching this node" so the label is respected.
- Launch method — "Launch agents via SSH".
- Host — the slave server's public IP address.
- Credentials — Kind: SSH Username with private key; add the slave's key-pair PEM content directly.
- Host Key Verification Strategy — select "Non verifying Verification Strategy".
- Availability — "Keep this agent online as much as possible".
Note: If Build Executor status shows an error, it is usually a Java version mismatch — install the same Java version on the slave that's on the master.
Running a Job on a Slave
Create a job → Configure → check "Restrict where this project can be run" → enter the Label (e.g. Linux) → add an Execute Shell build step → Save & Build. The job output will be found on the slave server, not the master — because the slave is working on behalf of the master.
Important: If the Label option is left blank inside a job, it always runs on the master.