DEV Community

Omkar Sharma
Omkar Sharma

Posted on

Complete Guide to Jenkins CI/CD Pipeline Setup on AWS EC2 (Ubuntu)

Developers from the Application team write the code and push it to GitHub.

Now, instead of manually building and deploying the application, we use Jenkins as a CI/CD tool to automate the entire process.

Here’s how the flow works:

  1. Developers commit and push the code to GitHub.
  2. Jenkins is connected to the repository using a webhook. Whenever new code is pushed, Jenkins automatically triggers a pipeline.
  3. Jenkins pulls the latest code and starts the build process.
  4. During the build stage, Docker is used to create a Docker image from that code.
  5. The Docker image is then pushed to a container registry (like Docker Hub or ECR).
  6. In the deployment stage, Jenkins deploys that image either:
  • On an Amazon EC2 instance, or
  • On a Kubernetes cluster.
  1. Once the application is live, monitoring tools like Prometheus are used to monitor application health, metrics, and performance.

Omkar Sharma

In Simple Terms

Jenkins acts as the brain of the CI/CD pipeline.

It automates:

  • Code integration (Continuous Integration)
  • Testing and building
  • Docker image creation
  • Deployment to servers or Kubernetes
  • And ensures the whole process runs automatically whenever new code is pushed

This is the concept of CI/CD using Jenkins β€” automation from code commit to production deployment and monitoring, without manual intervention.

Setting Up Jenkins on AWS EC2 (Ubuntu)

Launch EC2 Instance

  • Launch an Ubuntu Server EC2 instance.
  • Instance type: Free Tier eligible (e.g., t2.micro).
  • Storage: 15 GB (Free Tier eligible).
  • Allow Port 80 in the Security Group (HTTP traffic).
  • (Recommended) Also allow Port 8080 for Jenkins default access.

What is Jenkins?

Jenkins is a self-contained, open source automation server which can be used to automate all sorts of tasks related to building, testing, and delivering or deploying software.

Jenkins can be installed through native system packages, Docker, or even run standalone on any machine with a Java Runtime Environment (JRE) installed.

Installation Steps (Ubuntu/Debian)

Official Documentation:

https://www.jenkins.io/doc/book/installing/linux/#debianubuntu

Step 1: Update Packages

sudo apt update
Enter fullscreen mode Exit fullscreen mode

Step 2: Install Java (Required Before Jenkins)

sudo apt install fontconfig openjdk-21-jre
java -version
Enter fullscreen mode Exit fullscreen mode

Omkar Sharma

On Debian/Ubuntu, it is strongly recommended to install Java before Jenkins. If Jenkins is installed first and Java is added later, the Jenkins service may fail to start with:

jenkins: failed to find a valid Java installation
Enter fullscreen mode Exit fullscreen mode

Install Jenkins (Long Term Support Release)

sudo wget -O /etc/apt/keyrings/jenkins-keyring.asc \
  https://pkg.jenkins.io/debian-stable/jenkins.io-2026.key

echo "deb [signed-by=/etc/apt/keyrings/jenkins-keyring.asc]" \
  https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
  /etc/apt/sources.list.d/jenkins.list > /dev/null

sudo apt update
sudo apt install jenkins
Enter fullscreen mode Exit fullscreen mode

Check Jenkins Service Status

sudo systemctl status jenkins
Enter fullscreen mode Exit fullscreen mode

Omkar Sharma

If the service is active and running, Jenkins has been installed successfully.

To ensure Jenkins is active and running whenever you reboot or restart your server, check whether the service is enabled:

sudo systemctl is-enabled jenkins
Enter fullscreen mode Exit fullscreen mode
  • If the output is enabled, Jenkins will start automatically on boot.
  • If the output is disabled, run the following command:
sudo systemctl enable jenkins
Enter fullscreen mode Exit fullscreen mode

Access Jenkins in Browser

  1. Go to the Public IP of your EC2 instance.
  2. Open your browser and type:
http://<public-ip>:8080
Enter fullscreen mode Exit fullscreen mode

You will see the Getting Started page.

Omkar Sharma

Unlock Jenkins

You need to enter the initial admin password stored in the following file on your server:

sudo cat /var/lib/jenkins/secrets/initialAdminPassword
Enter fullscreen mode Exit fullscreen mode

Omkar Sharma

Copy the password and paste it into the Jenkins setup page.

Install Plugins

After unlocking Jenkins, click on:

Install suggested plugins

Omkar Sharma

Omkar Sharma

Omkar Sharma

Omkar Sharma

Congratulations you have setup the Jenkins


✍️ Author: Omkar Sharma

πŸ“¬ Feel free to connect on LinkedIn or explore more on GitHub

Top comments (0)