๐Ÿš€ Day 32: Setting Up Jenkins Agents! ๐Ÿค–

Ritesh DolareRitesh Dolare
3 min read

โœ…What is Jenkins? ๐Ÿ› ๏ธ

Before we get into agents, let's quickly recap what Jenkins is. Jenkins is like a superhero for developers. It helps automate repetitive tasks, like testing and deploying code, making the life of a developer much easier. Think of Jenkins as a smart assistant that handles all the boring stuff for you.

โœ…Meet the Master and the Agents! ๐ŸŽฉ๐Ÿ‘ฅ

In Jenkins, we have two main players: the Master and the Agents.

Day 28 Task: Jenkins Agents

Jenkins Master (Server) ๐ŸŽฉ

  • Role: The boss that manages everything.

  • Tasks: Schedules jobs, monitors their status, and serves the Jenkins user interface (UI).

  • Think of it as: A conductor of an orchestra, making sure everyone is playing their part.

Jenkins Agent ๐Ÿ‘ฅ

  • Role: The worker that does the actual job.

  • Tasks: Executes tasks defined by the Jenkins jobs.

  • Think of it as: A musician in the orchestra, playing the notes assigned by the conductor.

โœ…Why Do We Need Agents? ๐Ÿค”

For small projects, having just the Jenkins master might be enough. But as projects grow and you have more tasks, it's better to have multiple agents to share the workload. This way, jobs get done faster and more efficiently.

โœ…Let's Set Up an Agent! ๐Ÿ› ๏ธ

To set up an agent, we'll use an AWS EC2 instance (a virtual machine in the cloud) with Ubuntu 22.04. Here's a step-by-step guide:

Step 1: Create an AWS EC2 Instance ๐Ÿ–ฅ๏ธ

  1. Launch a New Instance:

    • Go to the AWS Management Console.

    • Launch a new EC2 instance with Ubuntu 22.04.

    • Choose an instance type like t2.micro (good for small tasks).

    • Configure security settings to allow SSH access.

  2. Connect to Your Instance:

    • Use SSH to connect to your instance. Open your terminal and type:

        ssh -i /path/to/your-key.pem ubuntu@your-ec2-instance-public-dns
      

Step 2: Install Java and Docker on Your Agent โ˜•๐Ÿ‹

  1. Install Java:

    • Update your package list:

        sudo apt update
      
    • Install Java:

        sudo apt install openjdk-11-jdk -y
      
  2. Install Docker:

    • Install Docker with:

        sudo apt install docker.io -y
      
    • Start Docker:

        sudo systemctl start docker
        sudo systemctl enable docker
      

Step 3: Connect the Agent to Jenkins Master ๐ŸŒ

  1. Generate SSH Key Pair on Master:

    • On your Jenkins master server, generate an SSH key pair:

        ssh-keygen -t rsa -b 4096 -C "jenkins-agent"
      
    • Copy the public key to your agent:

        ssh-copy-id -i ~/.ssh/id_rsa.pub ubuntu@your-ec2-instance-public-dns
      
  2. Set Up Jenkins Agent Node:

    • In Jenkins UI, go to Manage Jenkins > Manage Nodes and Clouds > New Node.

    • Enter node details and set up using SSH with the credentials.

  3. Verify Agent Status:

    • Check the "Nodes" section in Jenkins to see if the agent is connected.

โœ…Running Jobs on the New Agent ๐Ÿƒโ€โ™‚๏ธ

Now that your agent is set up, let's run some jobs!

Step 1: Label Your Agent ๐Ÿท๏ธ

  • Go to Manage Jenkins > Manage Nodes and Clouds > your-agent > Configure.

  • Add labels to your agent.

Step 2: Run Jobs ๐ŸŽ‰

  • Configure your jobs to use the new agent's label.

  • Run the jobs you built on Day 26 and Day 27 on the new agent.

โœ…Conclusion ๐ŸŽ‡

Setting up Jenkins agents helps distribute the workload, making your projects run smoother and faster. By following these steps, you've taken a big step towards mastering Jenkins! Keep up the great work, and see you tomorrow for more DevOps adventures! ๐Ÿš€

Feel free to ask any questions or share your progress. Let's learn and grow together! ๐ŸŒฑ

Happy DevOps-ing! ๐ŸŽ‰

1
Subscribe to my newsletter

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

Written by

Ritesh Dolare
Ritesh Dolare

๐Ÿ‘‹ Hi, I'm Ritesh Dolare, a DevOps enthusiast dedicated to mastering the art of DevOps.