This guide walks through setting up a complete CI/CD pipeline using GitHub Actions with SonarQube for code quality, Nexus for artifact storage, and Tomcat for deployment, all hosted on AWS EC2 instances.
Purpose: Code Quality & Static Analysis
Go to AWS EC2 Console → Launch Instance
Select Ubuntu 22.04 LTS as AMI
Choose an instance type (Recommended: t2.medium or higher)
Select your Key Pair
Configure security group → allow Port 9000
Launch the instance
Copy SSH command from AWS console
Connect from your terminal:
ssh -i <keypair.pem> ubuntu@
Install the latest version of Java:
sudo apt update sudo apt install openjdk-17-jdk -y java -version
Download and install SonarQube:
wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-10.4.1.87278.zip
unzip sonarqube-10.4.1.87278.zip
cd sonarqube-10.4.1.87278/bin/linux-x86-64
./sonar.sh start
./sonar.sh status
http://:9000
Default credentials: admin / admin
Generate a Sonar Token for GitHub Actions.
Purpose: Artifact Repository
Go to AWS EC2 Console → Launch Instance
Select Ubuntu 22.04 LTS as AMI
Choose an instance type
Select your Key Pair
Allow Port 8081
wget https://download.sonatype.com/nexus/3/nexus-3.85.0-03-linux-x86_64.tar.gz
tar -xvf nexus-3.85.0-03-linux-x86_64.tar.gz
mv nexus-3.85.0-03 nexus
./nexus/bin/nexus start
http://:8081
Purpose: Deployment Server
Go to AWS EC2 Console → Launch Instance
Select Ubuntu 22.04 LTS as AMI
Choose an instance type
Select your Key Pair
wget https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.112/bin/apache-tomcat-9.0.112.tar.gz
tar -xvzf apache-tomcat-9.0.112.tar.gz
cd apache-tomcat-9.0.112/bin
./startup.sh
Edit /etc/tomcat9/tomcat-users.xml and add:
Go to GitHub Repository → Settings → Secrets and Variables → Actions
Click New Repository Secret and add the following:
Secret Name Description
SONAR_HOST_URL SonarQube Server URL
SONAR_TOKEN Generated Token
NEXUS_USER Nexus Username
NEXUS_PASS Nexus Password
TOMCAT_USER Tomcat Username
TOMCAT_PASS Tomcat Password
In your repository, create a new file:
.github/workflows/ci-cd.yml
Paste your pipeline YAML configuration and commit changes.
Navigate to the Actions tab — your CI/CD pipeline will start automatically on a new push to main.
After successful execution:
SonarQube: Code Analysis Report
Nexus: Stored Build Artifacts
Tomcat: Deployed Application
A fully automated CI/CD pipeline that:
Analyzes code with SonarQube
Stores artifacts in Nexus
Deploys to Tomcat automatically via GitHub Actions