Jenkins Master–Slave Architecture

Jenkins Master–Slave Architecture 

Jenkins Master and Slave (Agent) – Real-World Scenario

Imagine Jenkins Master as a manager and Slaves (Agents) as workers.

  • Master decides what to build and when

  • Slaves actually do the work

  • Communication happens via SSH

  • Each slave can run builds independently

  • Load is distributed → faster builds, no overload

Why Master–Slave is Used

  • Distributes builds across machines

  • Reduces load on Jenkins master

  • Supports parallel builds

  • Allows builds on different OS platforms

Key Concepts

  • Master: Scheduling, job control, UI

  • Slave (Agent): Executes builds

  • Java: Mandatory on slave

  • Labels: Used to target jobs to specific slaves

  • Executors: Number of parallel jobs a slave can run


Setting Up Jenkins Slave (Agent)

Step 1: Create a Server and Install Java & Maven

Run these commands on the slave server:

sudo apt update sudo apt install -y wget gnupg wget -qO - https://repos.azul.com/azul-repo.key | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/azul.gpg echo "deb https://repos.azul.com/zulu/deb stable main" | sudo tee /etc/apt/sources.list.d/zulu.list sudo apt update sudo apt install -y zulu8-jdk sudo apt install -y maven

⚠️ Important Note
Do not install Java 17 unless required by the build:

sudo apt install -y openjdk-17-jdk update-alternatives --config java

Step 2: Configure Slave in Jenkins UI

Path:

Dashboard → Manage Jenkins → Nodes → New Node

Fill the configuration:

  • Node Name: abc

  • Type: Permanent Agent

  • Executors: 3 (parallel builds)

  • Remote Root Directory: /tmp

  • Labels: slave1

  • Usage: Use this node as much as possible

  • Launch Method: Launch agents via SSH

  • Host: Slave private IP

  • Credentials:

    • Kind: SSH username with private key

    • Username: ubuntu

    • Private key: .pem file

  • Host Key Verification: Non-verifying

Save the node.


Step 3: Run Job on Slave

  • Open Job → Configure

  • Enable Restrict where this project can be run

  • Enter label: slave1

  • Save and build

✅ Job will now execute on the slave machine.

Comments

Popular posts from this blog

Managing Amazon EBS Volumes and Snapshots Across Regions

Git for Beginners: Complete Guide from Installation to First Push on GitHub

AWS - Amazon Web Services