🧠 Jenkins Master-Agent Architecture Explained: Setup, Usage & CI Pipeline Integration (Ubuntu)

Jenkins is a powerful open-source automation server used to implement CI/CD (Continuous Integration and Continuous Delivery) pipelines. One of its key features is the Master-Agent architecture, which helps distribute workloads across machines to improve scalability and performance.

This guide walks you through:

✔️ Jenkins Master and Agent concepts
✔️ Installation on Ubuntu (CLI-based)
✔️ Master-Agent connection setup
✔️ A simple CI pipeline using agents


🧠 1. Jenkins Master: Meaning & Definition

The Master Node is the core component of a Jenkins setup. It's responsible for orchestrating and managing the entire Jenkins environment.

🔑 Key Responsibilities:

  • Stores pipeline configurations

  • Distributes workloads to Agents

  • Manages plugins & security

  • Handles:

    • Job scheduling

    • Triggering builds

    • Managing build results

    • Communication with Agent nodes

🧾 Definition:

The Jenkins Master is the central server that manages jobs, schedules builds, and delegates tasks to agents for execution.


🧩 2. What is an Agent?

A Jenkins Agent (formerly known as "Slave" or "Worker Node") is any machine set up to execute build tasks sent by the master.

🤖 Also referred to as:

  • Agent = Worker = Slave = Node

✅ Use Cases:

  • Master: Manages pipelines and coordinates execution.

  • Agent: Executes tasks — such as compiling code, running tests, or deploying to production.

Agents can run in Docker containers, virtual machines, or physical remote servers — making them highly flexible for distributed builds.


🛠️ 3. Jenkins Master and Agent Installation ( on Ubuntu )

Let’s set up a basic Jenkins Master-Agent system using the command line.


🔧 Master Installation ( on Ubuntu ):

Run the following commands on the server you want to use as the Master Node:

sudo apt update
sudo apt install openjdk-11-jdk -y
wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -
sudo sh -c 'echo deb https://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
sudo apt update
sudo apt install jenkins -y
sudo systemctl start jenkins

Now, Jenkins will be available on http://your_server_ip:8080.


🧩 Agent Setup

On the Agent Machine, install Java, Docker, and Git:

bashCopyEditsudo apt install -y openjdk-17-jdk git docker.io
sudo usermod -aG docker $USER  # Optional: If you want to run container-based builds

Then go to the Jenkins UI:

Manage Jenkins → Manage Nodes → New Node

Choose Permanent Agent, and configure:

  • Remote root directory: /home/jenkins

  • Launch method: Launch agent via SSH

  • Add SSH credentials to connect the master to the agent


🔗 4. Agent Integration & Verification

After setting up the agent:

Go to Manage Jenkins → Nodes

  • ✅ Verify the agent shows as Connected

  • 🏷 Assign a label like dev-server


✨ Pipeline Using Agent

Here’s a basic Jenkins pipeline that runs on a labeled agent:

groovyCopyEditpipeline {
  agent { label 'dev-server' }
  stages {
    stage('Clone') {
      steps {
        git 'https://github.com/user/app.git'
      }
    }
    stage('Build') {
      steps {
        sh 'sudo apt-get install docker.io'
      }
    }
  }
}

📦 5. Push Docker Image to DockerHub (with PAT)

Once Jenkins is building on the agent, let’s push a Docker image to Docker Hub.

📌 Prerequisites:

  • Docker installed on the agent

  • Docker Hub PAT (Personal Access Token)


🔐 Step 1: Store DockerHub Credentials

  1. Go to Jenkins → Credentials → System → Global Credentials

  2. Add a Username + Password, where the password is your Docker Hub PAT


🧾 Step 2: Jenkinsfile to Build & Push

pipeline {
  agent { label 'dev-server' }
  stages {
    stage('Build & Push') {
      steps {
        script {
          withCredentials([usernamePassword(credentialsId: 'docker-creds', usernameVariable: 'DOCKER_USER', passwordVariable: 'DOCKER_PASS')]) {
            sh """
              docker build -t $DOCKER_USER/node-app:latest .
              echo $DOCKER_PASS | docker login -u $DOCKER_USER --password-stdin
              docker push $DOCKER_USER/node-app:latest
            """
          }
        }
      }
    }
  }
}

Verify:
Check your Docker Hub account to confirm the image is successfully pushed!


🎯 Final Thoughts

Setting up a Jenkins Master-Agent system is essential for scaling your CI/CD workflows across environments. By integrating Docker, GitHub, and secure credential handling, your pipelines become more modular, powerful, and production-ready.

0
Subscribe to my newsletter

Read articles from ABHISHEK WAGHMARE directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

ABHISHEK WAGHMARE
ABHISHEK WAGHMARE

An Introduction To DevOps: Where Development And Operations Meet 🔍 My DevOps learner journey has been inspired by a true passion for continual personal development and a genuine curiosity for cloud and automation technologies. With the practice of engaging in numerous online coursework and community threads, I have built a growing comprehension of what is necessary for everyday life in the tools offered from Docker, Jenkins, and Kubernetes, which are mandatories in the IT Society. 🛠 What sets me apart? A commitment to practical application. Through personal projects, I actively implement my learning to solve real-world problems, gaining hands-on experience. This proactive approach helps me not only understand technologies at a surface level but to deeply integrate them into effective solutions. My ultimate goal? To merge innovative DevOps practices with business objectives to streamline operations and boost productivity in any tech landscape. I am eager to bring my fresh perspective and evolving expertise to a vibrant team, where continuous learning is intertwined with company growth. 📨 Let’s connect and explore how we can drive progress together in the fascinating world of DevOps!