End-to-End CI/CD Pipeline: From GitHub to Docker Hub Using Jenkins

🚀 Automating Java Application Deployment with Maven, Docker, and Jenkins
Introduction
In this blog post, I’ll walk you through how I automated the end-to-end build and deployment process of a Java application using Maven, Docker, and Jenkins. From compiling the code to pushing a Docker image into Docker Hub, this pipeline demonstrates a real-world DevOps workflow.
🧩 Prerequisites
Basic knowledge of Git, Maven, Docker, and Jenkins
Installed: Git, Java, Maven, Docker, Jenkins
GitHub repository with a Java project (Spring Boot preferred)
🔧 Step 1: Build the Application Using Maven
Explain how you cloned your GitHub repo and used Maven to generate the .jar
file.
Commands used:
bashCopyEditmvn clean package
📦 Step 2: Dockerize the Application
Show your Dockerfile
and explain each line.
Sample Dockerfile:
DockerfileCopyEditFROM openjdk:17
COPY target/myapp.jar app.jar
ENTRYPOINT ["java", "-jar", "app.jar"]
🧪 Step 3: Test Docker Image Locally
Build and run the Docker image locally.
bashCopyEditdocker build -t myapp .
docker run -p 8080:8080 myapp
🚀 Step 4: Push Docker Image to Docker Hub
Tag and push the Docker image.
bashCopyEditdocker tag myapp mydockerhubusername/myapp
docker push mydockerhubusername/myapp
🤖 Step 5: Automate the Workflow with Jenkins
Describe how you used the Docker Pipeline plugin in Jenkins.
- Jenkinsfile example:
pipeline {
agent any
stages {
stage('Clone') {
steps {
git 'https://github.com/your-username/your-repo.git'
}
}
stage('Build with Maven') {
steps {
sh 'mvn clean package'
}
}
stage('Build Docker Image') {
steps {
script {
dockerImage = docker.build("your-dockerhub-username/your-image-name")
}
}
}
stage('Push to Docker Hub') {
steps {
script {
docker.withRegistry('https://index.docker.io/v1/', 'dockerhub-credentials-id') {
dockerImage.push('latest')
}
}
}
}
}
}
Subscribe to my newsletter
Read articles from BHASHWANTH PALUKURI directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
