← Back to list

Streamlining CI/CD Pipelines with Dynamic EC2 Agents in Jenkins

Introduction: Continuous Integration and Continuous Delivery (CI/CD) are crucial practices in modern software development, enabling teams…

Ayushmaan Srivastav · 2024-03-16 21:33 · 0 claps · 2.7 min read
#100daychallenge #technical-transformation #day-39 #jenkins #ec2
Open on Medium ↗
Wiki topics: AGT · AI Agents 💻 · Programming ☁️ · DevOps & Cloud

Streamlining CI/CD Pipelines with Dynamic EC2 Agents in Jenkins

Introduction: Continuous Integration and Continuous Delivery (CI/CD) are crucial practices in modern software development, enabling teams to deliver high-quality software at a rapid pace. Jenkins has been a cornerstone tool for automating CI/CD pipelines, but traditional static agents can present challenges in resource management and scalability. In this guide, we’ll explore how to leverage Amazon EC2 instances as dynamic agents in Jenkins to optimize resource utilization and streamline CI/CD pipelines.

Prerequisites:

  1. An AWS account with permissions to create and manage EC2 instances.
  2. A Jenkins server set up and running.
  3. Basic familiarity with Jenkins and AWS services.

Step-by-Step Guide:

Step 1: Set Up an Amazon EC2 Instance

  • Log in to the AWS Management Console.
  • Navigate to the EC2 dashboard.
  • Click on “Launch Instance” to create a new EC2 instance.
  • Choose an Amazon Machine Image (AMI) based on your requirements (e.g., Amazon Linux, Ubuntu, etc.).
  • Select an instance type based on your workload needs and budget.
  • Configure instance details such as the number of instances, network settings, and storage.
  • Add tags for easier identification.
  • Configure security groups to allow inbound traffic to your Jenkins server (e.g., SSH, HTTP, HTTPS).
  • Review and launch the instance.

Step 2: Install Java and Jenkins Prerequisites on the EC2 Instance

  • SSH into the EC2 instance using the public IP or DNS provided.
  • Update the package repository: sudo yum update (for Amazon Linux) or sudo apt update (for Ubuntu).
  • Install Java Development Kit (JDK): sudo yum install java (for Amazon Linux) or sudo apt install openjdk-19-jdk (for Ubuntu).
  • Verify Java installation: java -version.
  • Add the Jenkins repository key: wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -.
  • Add the Jenkins repository to your package sources: sudo sh -c 'echo deb https://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list' (for Ubuntu).
  • Install Jenkins: sudo apt update && sudo apt install jenkins.
  • Start the Jenkins service: sudo systemctl start jenkins.
  • Enable Jenkins to start on boot: sudo systemctl enable jenkins.
  • Verify Jenkins installation by accessing Jenkins on port 8080 of your EC2 instance’s public IP or DNS (http://<EC2_Public_IP>:8080).

Step 3: Configure Jenkins to Use EC2 Instances as Agents

  • Install the “Amazon EC2” plugin in Jenkins:
  • Navigate to the Jenkins dashboard.
  • Go to “Manage Jenkins” -> “Manage Plugins” -> “Available” tab.
  • Search for “Amazon EC2” and install the plugin.
  • Configure the Amazon EC2 cloud in Jenkins:
  • Go to “Manage Jenkins” -> “Configure System”.
  • Scroll down to the “Cloud” section and click on “Add a new cloud” -> “Amazon EC2”.
  • Fill in the AWS credentials (Access Key ID and Secret Access Key).
  • Configure the EC2 region, AMI ID, instance type, and other settings according to your requirements.
  • Save the configuration.

Step 4: Define EC2 Templates for Jenkins Agents

  • Under the Amazon EC2 cloud configuration, click on “Add” next to “Instance Templates”.
  • Configure the EC2 template with specifications such as the AMI ID, instance type, subnet ID, security groups, and any custom user data or scripts required.
  • Define labels for the EC2 template to identify them in Jenkins jobs.
  • Save the template.

Step 5: Create a Jenkins Job to Use EC2 Agents

  • Create a new Jenkins job or configure an existing one.
  • In the job configuration, specify the label(s) defined for the EC2 template(s) in the “Restrict where this project can be run” field.
  • Configure the build steps, SCM (Source Code Management) settings, triggers, and post-build actions as needed.
  • Save the job configuration.

Step 6: Test the Jenkins Job with EC2 Agents

  • Trigger the Jenkins job and observe the provisioning of EC2 instances as agents.
  • Monitor the job execution on the dynamically provisioned EC2 agents.
  • Verify the successful completion of the job.

Conclusion: By leveraging Amazon EC2 instances as dynamic agents in Jenkins, teams can optimize resource utilization, enhance scalability, and streamline CI/CD pipelines. With the step-by-step guide provided, organizations can easily set up and configure dynamic EC2 agents in Jenkins, empowering them to accelerate their software delivery processes on the AWS cloud.


메타데이터
post_id
bb75adc03035
slug
streamlining-ci-cd-pipelines-with-dynamic-ec2-agents-in-jenkins-bb75adc03035
url
https://medium.com/@srivastavayushmaan1347/streamlining-ci-cd-pipelines-with-dynamic-ec2-agents-in-jenkins-bb75adc03035
canonical_url
https://medium.com/@srivastavayushmaan1347/streamlining-ci-cd-pipelines-with-dynamic-ec2-agents-in-jenkins-bb75adc03035
author_url
https://medium.com/@srivastavayushmaan1347
status
ok
fetched_at
2026-07-24 05:50:58