A complete CI/CD pipeline implementation using Jenkins, Docker, and AWS EC2 for a Spring Boot application.
This project demonstrates a fully automated CI/CD pipeline that:
- Builds a Java Maven Spring Boot application
- Packages it as a Docker container
- Deploys it to AWS EC2 using Jenkins Pipeline
This repository maintains three specialized branches with distinct purposes:
- Purpose: Production-ready code and stable documentation
- Contains:
- Latest stable version of the application source code
- Project documentation and setup guides
- Asset files and screenshots
- Core configuration files
- Purpose: Active CI/CD pipeline execution and automation
- Functionality:
- Automated Version Management: Increments Maven version numbers automatically (e.g., 1.1.0 → 1.1.1)
- Continuous Integration: Builds Java Maven application and runs tests
- Docker Operations: Builds Docker images and pushes to Docker Hub (
harshwardhan07/harshwardhan:jenkinsJMA-1.0
) - AWS EC2 Deployment: Deploys containerized application to EC2 instance via SSH
- Auto-commit: Commits version bumps back to jenkins-jobs branch automatically
- Pipeline Monitoring: Tracks build history and deployment status
- Purpose: Reusable Jenkins pipeline functions
- Contains:
vars/buildJar.groovy
- Maven build functionvars/buildImage.groovy
- Docker build and push function with error handlingvars/deployApp.groovy
- Deployment function- Shared pipeline utilities and common functions
jenkins-jobs branch → Jenkins Pipeline → Docker Hub → AWS EC2
↓ ↓ ↓ ↓
Version increment Build & Test Push Image Deploy App
Auto-commit Use shared lib Registry Live service
Key Features of jenkins-jobs branch:
- ✅ Fully automated CI/CD pipeline with 5 stages
- ✅ Automatic version incrementation and Git commits
- ✅ Docker image building with permission handling
- ✅ AWS EC2 deployment with SSH automation
- ✅ Enhanced error handling and troubleshooting
- ✅ Integration with shared library functions
GitHub Repository → Jenkins Pipeline → Docker Build → AWS EC2 Deployment
- Backend: Java 8, Spring Boot 2.3.5
- Build Tool: Maven
- CI/CD: Jenkins Pipeline (Declarative)
- Containerization: Docker
- Cloud: AWS EC2
- Version Control: Git/GitHub
- Java 8+
- Maven 3.6+
- Jenkins with required plugins
- Docker
- AWS EC2 instance
- GitHub repository access
- Clone the repository
git clone https://github.com/HarshwardhanPatil07/JMA-jenkins-docker-AWS.git cd JMA-jenkins-docker-AWS
Configure these credentials in Jenkins:
-
GitHub Credentials (
github-credentials
)- Type: Username with password
- Username: Your GitHub username
- Password: Personal Access Token (PAT)
⚠️ Note: PAT expires every 30 days - update regularly
-
EC2 Server Key (
ec2-server-key
)- Type: SSH Username with private key
- ID:
ec2-server-key
- Username:
ec2-user
- Private Key: Your EC2 instance .pem file content
The Jenkinsfile defines three stages:
- Test Stage - Runs application tests
- Build Stage - Builds the Maven application
- Deploy Stage - Deploys Docker container to EC2
The pipeline deploys the application using:
docker run -p 3080:3080 -d harshwardhan07/my-app:1.0
-
Credential Expiry
- GitHub PAT expires every 30 days
- Update credentials in Jenkins:
Dashboard → Manage Jenkins → Credentials
-
EC2 Connection Issues
- Verify security group allows SSH (port 22)
- Check EC2 instance public IP
- Ensure .pem file permissions are correct
-
Docker Pull Issues
- Verify Docker image exists in registry
- Check network connectivity from EC2 to Docker Hub
Check the pipeline console output for detailed logs:
- Available in Jenkins job → Build History → Console Output
- Sample output available in
#18-Pipeline-Console-Output.txt