DevOps CI/CD Project: Jenkins CI/CD Pipeline on AWS with ECR, Docker, Prometheus, Grafana & Alertmanager

Amay JaiswalAmay Jaiswal
5 min read

Introduction

This blog is a complete beginner-friendly guide to setting up a real-world DevOps CI/CD pipeline. You will:

  • Deploy a Jenkins CI/CD pipeline on AWS EC2

  • Build a Java application into a Docker image

  • Push the image to AWS ECR

  • Monitor everything with Prometheus, Grafana, and Alertmanager

  • Set up GitHub Webhooks to trigger pipelines on code changes

At the end of this project, you'll have a working end-to-end DevOps CI/CD system. Even better, you'll be confident enough to showcase it on your resume and explain it in interviews.

Let me know if you want help designing visuals or diagrams!


Prerequisites

  • AWS Free Tier Account

  • Basic understanding of Java, Docker, and AWS services

  • GitHub account

  • Terminal access (Linux/WSL/macOS recommended)


Project Phases Breakdown

Phase 1: Setup Local Java Project with Docker

Step 1: Create a directory structure:

mkdir java-cicd-project && cd java-cicd-project

Step 2: Create a sample Java app (Maven-based):

mvn archetype:generate -DgroupId=com.example -DartifactId=helloworld -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
cd helloworld

Step 3: Add a simple HelloWorld.java file under src/main/java/com/example/

package com.example;
public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, DevOps World!");
    }
}

Step 4: Add Dockerfile:

FROM openjdk:11-jdk
COPY target/helloworld-1.0-SNAPSHOT.jar app.jar
ENTRYPOINT ["java", "-jar", "app.jar"]

Phase 2: Launch AWS EC2 and Install Jenkins, Docker, Java

Step 1: Launch EC2 Instance

  • Go to AWS Console → EC2 → Launch Instance

  • AMI: Amazon Linux 2 (Free Tier)

  • Instance Type: t2.micro

  • Allow SSH (22), HTTP (80), Custom TCP (8080) for Jenkins

  • Launch and SSH into it

Step 2: Install Java, Docker, Jenkins:

sudo yum update -y
sudo yum install java-11-openjdk-devel git -y
sudo yum install docker -y
sudo service docker start
sudo usermod -aG docker ec2-user

sudo wget -O /etc/yum.repos.d/jenkins.repo \
    https://pkg.jenkins.io/redhat-stable/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
sudo yum install jenkins -y
sudo systemctl start jenkins
sudo systemctl enable jenkins

Step 3: Access Jenkins:

  • http://:8080

  • Get password: sudo cat /var/lib/jenkins/secrets/initialAdminPassword

  • Install suggested plugins + create admin user


Phase 3: AWS CLI and ECR Setup

Step 1: Install AWS CLI and Configure:

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
aws configure

Step 2: Create ECR Repository:

aws ecr create-repository --repository-name java-cicd-ecr --region us-east-1

Phase 4: Jenkins Plugins and Pipeline Setup

Step 1: Install Plugins:

  • Manage Jenkins > Manage Plugins > Install:

    • Amazon ECR

    • Docker Pipeline

    • GitHub Integration

Step 2: Configure Credentials:

  • AWS: Manage Jenkins → Credentials → Add AWS access/secret keys

Step 3: Create Pipeline Job:

  • Jenkins > New Item > Pipeline > Configure

Example Pipeline Script:

pipeline {
    agent any
    environment {
        IMAGE_NAME = 'java-cicd-ecr'
        AWS_ACCOUNT_ID = '<your-aws-account-id>'
        REGION = 'us-east-1'
        REPO_URI = "$AWS_ACCOUNT_ID.dkr.ecr.$REGION.amazonaws.com/$IMAGE_NAME"
    }
    stages {
        stage('Clone') {
            steps {
                git 'https://github.com/your-username/java-cicd-project.git'
            }
        }
        stage('Build JAR') {
            steps {
                sh 'mvn clean install'
            }
        }
        stage('Build Docker Image') {
            steps {
                sh 'docker build -t $IMAGE_NAME .'
            }
        }
        stage('Push to ECR') {
            steps {
                sh '''
                    aws ecr get-login-password --region $REGION | docker login --username AWS --password-stdin $REPO_URI
                    docker tag $IMAGE_NAME:latest $REPO_URI:latest
                    docker push $REPO_URI:latest
                '''
            }
        }
    }
}

Phase 5: GitHub Webhook for Trigger

Step 1: Jenkins > Configure Global Security > Enable GitHub Webhooks

Step 2: GitHub Repo > Settings > Webhooks:

  • Payload URL: http://<your-ec2-ip>:8080/github-webhook/

  • Content Type: application/json

  • Event: Just the push event


Phase 6: Monitoring with Prometheus, Grafana, Alertmanager

Step 1: Install Docker Compose:

sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

Step 2: Create monitoring setup:

mkdir monitoring && cd monitoring

docker-compose.yml

version: '3'
services:
  prometheus:
    image: prom/prometheus
    ports:
      - "9090:9090"
    volumes:
      - ./prometheus.yml:/etc/prometheus/prometheus.yml

  grafana:
    image: grafana/grafana
    ports:
      - "3000:3000"

  alertmanager:
    image: prom/alertmanager
    ports:
      - "9093:9093"
    volumes:
      - ./alertmanager.yml:/etc/alertmanager/config.yml

prometheus.yml

global:
  scrape_interval: 15s
scrape_configs:
  - job_name: 'jenkins'
    static_configs:
      - targets: ['host.docker.internal:8080']

alertmanager.yml (for basic alerting):

route:
  receiver: 'team-email'
receivers:
  - name: 'team-email'
    email_configs:
      - to: 'your-email@example.com'

Step 3: Launch:

docker-compose up -d

Final Phase: Clean Up Resources (To Save Cost)

Delete AWS Resources:

  • Terminate EC2 instance

  • Delete ECR repository

Delete Local Docker Containers:

docker-compose down

Final Flow Explanation (For Interviews)

  1. Developer pushes code to GitHub → GitHub webhook triggers Jenkins

  2. Jenkins pipeline clones the repo, builds Java app, creates Docker image

  3. Jenkins logs into AWS ECR and pushes Docker image

  4. Prometheus scrapes metrics, Grafana visualizes, and Alertmanager sends alerts if Jenkins is down


What You Achieved

✅ You built and deployed an automated CI/CD pipeline from scratch using AWS, Docker, and Jenkins.

✅ You integrated monitoring and alerting for real-time feedback.

✅ You used industry tools and infrastructure as close to real production as possible while staying in the free tier.

✅ You’re now ready to confidently showcase this in your resume and explain it to any interviewer.


Showcase This on Resume

DevOps CI/CD Pipeline Project (AWS + Jenkins + Docker + ECR)

  • Built a Java app, containerized with Docker, and pushed image to AWS ECR via Jenkins pipeline.

  • Automated pipeline trigger via GitHub webhook.

  • Integrated Prometheus and Grafana for monitoring with alerting via Alertmanager.

  • Deployed entirely on AWS EC2 Free Tier.


1
Subscribe to my newsletter

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

Written by

Amay Jaiswal
Amay Jaiswal

AWS Cloud & DevOps Engineer | Cloud Computing | Linux | Terraform & CloudFormation | AWS (EC2, S3, Lambda, API Gateway, DynamoDB, IAM) | Docker | Jenkins | CI/CD Pipelines | MySQL | Java | Jira | Postman | Git/GitHub