Day 28- Empowering Jenkins Workflows with Agents (Dec 24, 2023)
As we embark on the 28th day of the #90DaysOfDevOps Challenge, we delve into the realm of Jenkins agents—essential components that extend the capabilities of our Jenkins master server. In this blog post, we'll explore the significance of Jenkins agents, set up a new agent using an AWS EC2 instance, and seamlessly run previous jobs on this newly configured agent.
Understanding Jenkins Master and Agents:
Jenkins master servers act as the control center, orchestrating workflows, scheduling jobs, and monitoring overall pipeline activities. However, when it comes to execution, Jenkins leverages agents—individual machines or containers connected to the master. Agents handle the actual execution of steps defined in a job, providing scalability as your project requirements grow.
Before diving into the tasks, let's ensure our environment is set up correctly. For this tutorial, we assume a fresh Ubuntu 22.04 Linux installation. Key prerequisites include Java (matching the version on the Jenkins master server) and Docker. It's crucial to separate rights, permissions, and ownership for Jenkins users to maintain a secure and organized setup.
Task-01: Setting Up a Jenkins Agent on AWS EC2 Instance
Create an AWS EC2 Instance:
Spin up a new EC2 instance on AWS, ensuring it's accessible from your Jenkins master server.
Establish an SSH connection to the newly created instance.
Configure Node on Jenkins:
In Jenkins, navigate to the "Manage Jenkins" section.
Select "Manage Nodes and Clouds" and then "New Node."
Configure the new node, providing details like the node name, usage, and launch method (SSH).
SSH Key Pair Exchange:
- Exchange public-private SSH key pairs between the master and agent for secure communication.
Verify Node Status:
- Confirm the successful connection by checking the node status under the "Nodes" section in Jenkins.
For a detailed guide, refer to this article.
Task-02: Running Previous Jobs on the New Agent
Now that our agent is up and running, let's extend our Jenkins workflows to utilize this newfound scalability.
- Modify your Jenkins Declarative Pipeline (from Day 26 and Day 27) to include labels for the agent. This ensures that specific jobs are executed on the designated agent.
- Configure your Jenkins master server to trigger builds on the newly connected agent using the assigned labels.
By incorporating agent labels into your pipeline, you enhance the flexibility and efficiency of your CI/CD workflows.
Reflection on #90DaysOfDevOps:
As we approach the end of the fourth week in the #90DaysOfDevOps Challenge, take a moment to reflect on your journey. The introduction of Jenkins agents opens up new possibilities for scaling your automation infrastructure. Share your experiences on LinkedIn, connect with fellow participants, and celebrate your progress in the challenge.