Skip to main content

Command Palette

Search for a command to run...

Jenkins Agents

Published
4 min read
Jenkins Agents
U

👨‍💻 DevOps Architect @ Hippo Technik, LLC Passionate about bridging the gap between development and operations, I'm a dedicated DevOps Engineer at 6D Technology. With a strong belief in the power of automation, continuous integration, and continuous delivery, I thrive in optimizing software development pipelines for efficiency and reliability. 🚀 Exploring the DevOps Universe In my articles, I delve into the fascinating world of DevOps, where I share insights, best practices, and real-world experiences. From containerization and orchestration to CI/CD pipelines and infrastructure as code, I'm here to demystify the complex and empower fellow developers and ops enthusiasts. 📝 Blogging for Knowledge Sharing As a tech enthusiast and a lifelong learner, I'm committed to sharing knowledge. My articles aim to simplify complex concepts and provide practical tips that help teams and individuals streamline their software delivery processes. 🌐 Connect with Me Let's connect and explore the ever-evolving landscape of DevOps together. Feel free to reach out, comment, or share your thoughts on my articles. Together, we can foster a culture of collaboration and innovation in the DevOps community. 🔗 Social Links LinkedIn: https://www.linkedin.com/in/unnati-gupta-%F0%9F%87%AE%F0%9F%87%B3-a62563183/ GitHub: https://github.com/DevUnnati 📩 Contact Have questions or looking to collaborate? You can reach me at unnatigupta527@gmail.com Happy Learning!!

Jenkins Master (Server):

Jenkins’s server or master node holds all key configurations. The Jenkins master server is like a control server that orchestrates all the workflow defined in the pipelines. For example, scheduling a job, monitoring the jobs, etc.

Jenkins Agent:

An agent is typically a machine or container that connects to a Jenkins master and this agent executes all the steps mentioned in a Job. When you create a Jenkins job, you have to assign an agent to it. Every agent has a label as a unique identifier.

When you trigger a Jenkins job from the master, the actual execution happens on the agent node that is configured in the job.

A single, monolithic Jenkins installation can work great for a small team with a relatively small number of projects. As your needs grow, however, it often becomes necessary to scale up. Jenkins provides a way to do this called “master to agent connection.” Instead of serving the Jenkins UI and running build jobs all on a single system, you can provide Jenkins with agents to handle the execution of jobs while the master serves the Jenkins UI and acts as a control node.

Configuring Agent on Jenkins:

Jenkins Agent is configured in multiple ways. Jenkins agents can be launched in physical machines, virtual machines, Kubernetes clusters, and Docker images.

Basic Requirements of Become a Jenkins Agent:

a) Java Installation ( Same Version on Agent or Master)

b) Network Connection to Jenkins Installation

c) Docker (Same Version)

Task-01

Create an agent by setting up a node on Jenkins. Create a new AWS EC2 Instance and connect it to the master(Where Jenkins is installed). The connection of the master and agent requires SSH and the public-private key pair exchange. Verify its status under the "Nodes" section.

Step 1: Create two EC2 instances, One use as "Jenkins Master" and Another use as "Jenkins Server".

Step 2: Now generate SSH-Key pair on Jenkins-Master

Step 3: Copy the Public key id_rsa.pub from Jenkins-Master and paste on Jenkins-Agent inside this file ".ssh/authorized_keys ".

Before Proceeding Please make sure Jenkins and Docker are successfully installed on both machines.

for Installing and Jenkins, you can go through these Articles:

Jenkins-installation: https://devunnatig.hashnode.dev/jenkins-basics

Docker-Installation: https://devunnatig.hashnode.dev/docker

Step 4: Create a directory in a particular location for storing all the data on the Jenkins-Agent EC2 instance and give all the required permissions.

Step 5: Now Go and Access Jenkins-Master, Jenkins GUI.

Step 6: Click on Manage Jenkins --> Manage Credentials --> Add new Credentials for connecting Jenkins Master to Jenkins Agent

To create credentials you have to copy the private key and give it directly.

Follow this Article:

https://devunnatig.hashnode.dev/jenkins-declarative-pipeline-with-docker

Step 6: Now Go to Manage Jenkins ---> Nodes for Creating Agent.

Step 7: Click on "New Node" to create a New agent.

Step 8: Give the Name to your New Agent and click on "Create".

Step 9: Use the Same Path in the Root directory, which was created in the previous step on the Jenkins-Agent Machine. Give Jenkins-Agent Machine Public-IP and use the same credentials that you created in the previous step."

Step 10: Congratulations! Now it's Successfully Created.

Task-02

Create a new pipeline and give an agent to run that. Use labels for the agent, your master server should trigger builds for the agent server.

Step 1: Create a new job

Step 2: Write a Pipeline for running that job using the newly created Agent.

pipeline {
    agent {
        label 'jenkins-agent-1'
    }

    environment {
        DOCKERHUB_CREDENTIALS = credentials('dockerhub')
    }

    stages {
        stage('Clone the repo') {
            steps {
                echo 'Cloning the repository:'
                git 'https://github.com/DevUnnati/node-todo-cicd.git'
            }
        }

        stage('Build') {
            steps {
                echo 'Building the ToDo application on Docker'
                sh 'docker build . -t jenkins-docker:latest'
            }
        }

        stage('Login to DockerHub') {
            steps {
                echo 'Login to DockerHub'
                sh "echo \$DOCKERHUB_CREDENTIALS_PSW | docker login -u \$DOCKERHUB_CREDENTIALS_USR --password-stdin"
            }
        }
    }
}

Step 3: Click on "Build Job" and Check your Console Output.

Congratulations, Your Pipeline is running Successfully.

In the Next Article, will go through the Interview Question of "Jenkins".

Thank you for giving your precious time to read this blog/article and if any suggestions or improvements are required on my blogs feel free to connect on LinkedIn Unnati Gupta.

More from this blog

D

DevOps Dynamics

44 posts

Hello, fellow tech enthusiasts! I'm Unnati Gupta, and I'm delighted to welcome you to my corner of the internet. My journey in the tech realm has been nothing short of exhilarating.