This project demonstrates how to set up a complete CI/CD pipeline using Jenkins, Maven, and Nexus on an Ubuntu server. The pipeline automates code build, artifact deployment to Nexus, and deployment to an Nginx web server.
- AWS EC2 Instance: Ubuntu Server (T2 Medium, 30 GB storage)
- Basic knowledge of Linux commands, Jenkins, Maven, and Docker
- Instance type: t2.medium
- Storage: 30 GB
Follow the official Jenkins installation guide: 👉 Jenkins Installation on Linux
sudo apt install maven -y- Installed version: Maven 3.8.7
sudo apt install docker.io -y
sudo docker pull sonatype/nexus3
sudo docker volume create nexus-data
sudo docker run -d -p 8081:8081 --name nexus -v nexus-data:/nexus-data sonatype/nexus3docker ps
docker exec -it nexus /bin/bash
cat /nexus-data/admin.passwordExample output:
da2a59b0-3c0d-4b8e-b309-fc5d3e0e7c0c
set nexus username = admin
set nexus password = admin123
Navigate to:
Manage Jenkins -> Tools -> Configure Maven installation
- Name:
M3 - MAVEN_HOME:
/usr/share/maven
Navigate to:
Manage Jenkins -> Managed Files -> Add new config (Global Maven settings.xml)
Add content:
<servers>
<server>
<id>maven-releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>maven-snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>ls -l /var/lib/jenkins/.m2/
mkdir -p /var/lib/jenkins/.m2
mkdir -p /var/lib/jenkins/.m2/repository
chown -R jenkins:jenkins /var/lib/jenkins/.m2
sudo chmod -R 755 /var/lib/jenkins/.m2
vim /var/lib/jenkins/.m2/settings.xmlAdd:
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>maven-releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>maven-snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>
</settings>Edit POM.xml with server IP (example: 192.168.18.141).
pipeline {
agent any
environment {
APP_NAME = "myapp"
MAVEN_REPO = "/tmp/maven-repo"
}
stages {
stage('Checkout Code') {
steps {
git branch: 'main', url: 'https://github.com/rohitrawat891997/register-app.git'
}
}
stage('Build with Maven') {
steps {
sh "mvn -Dmaven.repo.local=${MAVEN_REPO} clean package"
}
}
stage('Upload to Nexus') {
steps {
withMaven(maven: 'M3') {
sh "mvn -Dmaven.repo.local=${MAVEN_REPO} clean deploy -s /var/lib/jenkins/.m2/settings.xml -DskipTests"
}
}
}
stage('Download from Nexus') {
steps {
sh """
curl -u admin:admin123 -O \
http://192.168.18.141:8081/repository/maven-releases/com/github/jitpack/maven-simple/0.2-SNAPSHOT/maven-simple-0.2-SNAPSHOT.jar
"""
}
}
stage("Deploy using Dockerfile") {
steps {
sh """
docker run -itd --name=tomcat -e ALLOW_EMPTY_PASSWORD=yes -p 8082:8080 bitnami/tomcat
docker cp webapp/target/*.war tomcat:/opt/bitnami/tomcat/webapps
docker restart tomcat
"""
}
}
}
}
### Run these commands for permission
usermod -aG docker $USER
usermod -aG docker jenkins
newgrp
systemctl restart docker
Edit sudoers file:
sudo vim /etc/sudoersAdd:
jenkins ALL=(ALL) NOPASSWD: /bin/systemctl restart nginx, /bin/rm, /bin/cp
-
Jenkins pulls code from GitHub
-
Builds with Maven
-
Uploads artifacts to Nexus
-
Downloads artifact from Nexus
-
Deploys artifact to Tomcat