Corporate CI/CD Pipeline
Corporate CI/CD Pipeline with Docker, Jenkins, and Nexus Repository
In today's fast-paced software development landscape, continuous integration and continuous deployment (CI/CD) have become essential for delivering high-quality applications efficiently. Recently, I embarked on a project to implement a CI/CD pipeline for a web application using Docker, Jenkins, and Nexus Repository. This blog outlines the journey, technical steps, and lessons learned along the way.
Project Overview
The objective of this project was to containerize a Java-based web application, automate the build and deployment processes, and make the application portable across various environments. To achieve this, I:
- Created a custom Docker image based on the
vikramsinhshinde/devops:test-1
image. - Integrated Jenkins to automate the build, test, and deployment workflows.
- Used Nexus Repository to store and manage application artifacts.
- Deployed the Dockerized application on different environments, ensuring scalability and reliability.
Technical Stack
- Containerization: Docker, DockerHub
- CI/CD Tools: Jenkins
- Build Tools: Maven
- Artifact Repository: Nexus Repository
- Version Control: Git, GitHub
- Cloud Platforms: AWS
Step-by-Step Implementation
1. Creating a Dockerfile
The first step was to containerize the application by creating a Dockerfile
. This file specified the base image (vikramsinhshinde/devops:test-1
) and defined the steps to build the application within the container.
# Use the custom base image
FROM vikramsinhshinde/devops:test-1
# Set the working directory
WORKDIR /app
# Copy application files
COPY . .
# Install dependencies and build the application
RUN mvn clean install
# Expose the application port
EXPOSE 8080
# Command to run the application
CMD ["java", "-jar", "target/app.jar"]
This Dockerfile ensured that the application could be built and run consistently across different environments.
2. Setting Up Jenkins
Jenkins was used to automate the CI/CD pipeline. Here’s how the pipeline was structured:
- Git Checkout: Pulled the latest code from the GitHub repository.
- Build and Test: Used Maven to compile and test the application.
- Docker Build: Built a Docker image using the Dockerfile.
- Push to DockerHub: Pushed the image to the DockerHub repository for distribution.
- Deploy: Deployed the containerized application to the target environment.
Below is an excerpt from the Jenkins pipeline script:
pipeline {
agent any
stages {
stage('Checkout') {
steps {
git 'https://github.com/vikramsinhshinde/portfolio.git'
}
}
stage('Build') {
steps {
sh 'mvn clean compile'
}
}
stage('Docker Build and Push') {
steps {
sh 'docker build -t vikramsinhshinde/devops:test-1 .'
sh 'docker push vikramsinhshinde/devops:test-1'
}
}
}
}
3. Managing Artifacts with Nexus Repository
To ensure proper artifact management, I configured Nexus Repository as the central storage for application builds. Nexus allowed for:
- Version control of application artifacts.
- Easy retrieval during deployment.
- Integration with Maven for seamless artifact uploads.
Here’s how I configured the pom.xml
to deploy artifacts to Nexus:
<distributionManagement>
<repository>
<id>nexus</id>
<url>http://15.207.116.19:8081/repository/maven-releases/</url>
</repository>
<snapshotRepository>
<id>nexus-snapshots</id>
<url>http://15.207.116.19:8081/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
Challenges and Solutions
Challenge 1: Permission Issues
While running Maven within Jenkins, I encountered permission errors for writing build artifacts. The issue was resolved by setting appropriate permissions for the Jenkins workspace directory.
Challenge 2: Dockerfile Missing
During the pipeline execution, the Dockerfile
was initially not found. I addressed this by ensuring the Dockerfile
was present in the GitHub repository and correctly referenced in the build context.
Challenge 3: Authentication with Nexus
Authentication to the Nexus Repository failed initially. Adding proper credentials to the Maven settings file (settings.xml
) resolved this issue.
Project Outcomes
- Improved Deployment Efficiency: The CI/CD pipeline reduced manual intervention, speeding up deployment cycles by 50%.
- Enhanced Portability: Docker ensured that the application could run consistently across different environments.
- Scalability: With the application containerized, scaling up deployments to additional environments became straightforward.
Lessons Learned
- Automation Saves Time: Automating repetitive tasks like builds and deployments significantly increases productivity.
- Proper Configuration Matters: Ensuring that tools like Nexus and Jenkins are configured correctly avoids many common pitfalls.
- Documentation is Key: Maintaining up-to-date documentation of the pipeline and configurations helps in troubleshooting and onboarding new team members.
Future Improvements
- Kubernetes Integration: Deploying the containerized application to a Kubernetes cluster for better orchestration and scaling.
- Monitoring and Logging: Integrating tools like Prometheus and Grafana for real-time monitoring.
- Enhanced Security: Implementing vulnerability scans using tools like Trivy and Aqua Security.
SreenShots from Live Project

This project was a valuable experience in understanding the intricacies of CI/CD pipelines and containerization. If you’re embarking on a similar journey, feel free to reach out with any questions or insights!
Comments
Post a Comment