Automation is the backbone of modern software development, and Jenkins stands out as a leading tool in the world of Continuous Integration and Continuous Deployment (CI/CD) pipelines. Its capability to automate various stages of the delivery pipeline makes it indispensable. Today, we’ll guide you through the steps to set up Jenkins on an AWS EC2 Ubuntu instance, leveraging the power and flexibility of Amazon Web Services.
Step 1: Launch an EC2 Instance
Your journey begins by logging into your AWS account. Once logged in, navigate to the EC2 dashboard within the AWS Management Console. Here, you’ll launch a new instance by selecting the “Instances” section and opting to create a new instance. We’ll name this instance “Jenkins.” Select Ubuntu as the operating system for your instance, given its compatibility and support. Next, choose the Free Tier eligible Amazon Machine Image (AMI). For the instance type, go with t2.micro, which is suitable for basic testing and development purposes. Create a key pair, which we will refer to as “JenkinsKey” in this guide. This key pair is crucial for securely connecting to your instance. Download this key pair to your system for safekeeping, as you will need it later to access the instance. Finally, launch your instance.
Step 2: Connect to the Instance
Once your EC2 instance is up and running, copy the public DNS provided in your EC2 dashboard. Open Git Bash and navigate to the directory where your key pair is stored, typically the “Downloads” folder. Use the following SSH command to connect to your instance:
ssh -i "path_to_your_key.pem" ubuntu@your_instance_public_DNS
You should now be logged into your Ubuntu instance.
Step 3: Update the System and Install Java
Start by updating the system packages to ensure you have the latest updates:
sudo apt update
Next, install the Java Development Kit (JDK), which is necessary for running Jenkins:
sudo apt install openjdk-11-jdk
Verify the installation by checking the Java version:
java -version
You should see an output indicating that Java 11 is installed.
Step 4: Install Jenkins on Ubuntu 24.04
Add Jenkins key and repository to your system:
wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -
sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
OR
sudo wget -O /usr/share/keyrings/jenkins-keyring.asc https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
Then add the Jenkins repository because it is not added by default in the Ubuntu 24.04 sources list:
echo "deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc]" https://pkg.jenkins.io/debian-stable binary/ | sudo tee \ /etc/apt/sources.list.d/jenkins.list > /dev/null
Update the package list again:
sudo apt update -y
Proceed to install Jenkins:
sudo apt install jenkins -y
Enable and start the Jenkins service:
sudo systemctl enable jenkins
sudo systemctl start jenkins
Step 5: Configure Security Group
In your AWS Management Console, navigate to “Security Groups.” Edit the inbound rules of your security group to allow TCP traffic on port 8080 from Anywhere (0.0.0.0/0). This step ensures that Jenkins is accessible from your local machine.
Step 6: Access and Unlock Jenkins
With the setup complete, copy the public IP address of your EC2 instance. Open your web browser and enter the following URL:
http://your_instance_public_IP:8080
You will be prompted to unlock Jenkins. Retrieve the initial admin password using:
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
Copy and paste this password into the Jenkins setup page to proceed.
Step 7: Final Setup
Complete the Jenkins setup by installing the suggested plugins. Once the plugins are installed,
create your admin user and finalize the instance configuration. Congratulations!
Jenkins is now up and running on your EC2 instance, ready to streamline your CI/CD pipelines.
Conclusion
Setting up Jenkins on an AWS EC2 instance might seem daunting initially, but with these steps, you can have a robust CI/CD pipeline up and running quickly. This setup allows for scalable, automated processes, ensuring your development and deployment workflows are efficient and reliable. Happy automating!