This project demonstrates a complete CI pipeline setup using Jenkins, deployed on an AWS EC2 instance. The pipeline integrates with SonarQube for code quality analysis, Docker for containerization, Maven for build automation, and TRIVY for Docker image scanning.
- Project Overview
- Setup Instructions
- Step 1: Create EC2 Instance
- Step 2: Connect and Install Tools
- Step 3: Install Jenkins
- Step 4: Change Security Group
- Step 5: Access Jenkins Console
- Step 6: Retrieve Administrator Password
- Step 7: Install Suggested Plugins
- Step 8: Create First User
- Step 9: Create Pipeline Job
- Step 10: Add Pipeline Script as SCM
- Step 11: Add Required Plugins
- Step 12: Setup Docker
- Step 13: Install and Configure SonarQube
- Step 14: Install Maven
- Step 15: Install TRIVY
- Step 16: Integrate SonarQube with Jenkins
- Step 17: Add Docker Hub Credentials
- Step 18: Add Jenkins Shared Library
- Step 19: Verify Pipeline Execution
- Launch an EC2 Instance
- Instance Type: t2.medium
- EBS Volume: 30 GB
- Region: US-EAST-1
- Operating System: Ubuntu
-
Connect to EC2
- SSH into your EC2 instance.
- Switch to the root user:
sudo su
-
Install Required Tools
- Follow the installation commands from the provided script:
wget https://github.com/Hafeezbaig/tools_installation_scripts/raw/main/jenkins.sh chmod +x jenkins.sh ./jenkins.sh
- Follow the installation commands from the provided script:
- Install Jenkins
- Run the installation script for Jenkins:
wget https://github.com/Hafeezbaig/tools_installation_scripts/raw/main/jenkins.sh chmod +x jenkins.sh ./jenkins.sh
- Run the installation script for Jenkins:
- Update Security Group
- Allow necessary ports (e.g., HTTP, Jenkins port 8080) in the EC2 security group settings.
- Sign Into Jenkins
- Access Jenkins via
http://<EC2_PUBLIC_IP>:8080/.
- Access Jenkins via
- Get Admin Password
- Run the following command in the EC2 instance:
cat /var/lib/jenkins/secrets/initialAdminPassword
- Run the following command in the EC2 instance:
- Install Plugins
- Navigate to Manage Jenkins -> Manage Plugins and install all suggested plugins.
- Set Up User
- Follow the Jenkins setup wizard to create your first user.
- Create Pipeline Job
- Create a new Pipeline job in Jenkins.
- Configure SCM
- Use the pipeline script from:
https://github.com/Hafeezbaig/Java_app_3.0.git
- Use the pipeline script from:
- Install Additional Plugins
- Navigate to Manage Jenkins -> Manage Plugins -> Available Plugins and install:
- SonarQube Scanner
- SonarQube Generic Coverage
- Sonar Quality Gates
- Artifactory
- Jfrog
- Navigate to Manage Jenkins -> Manage Plugins -> Available Plugins and install:
-
Install Docker
- Follow the installation script for Docker:
wget https://github.com/Hafeezbaig/tools_installation_scripts/raw/main/docker.sh chmod +x docker.sh ./docker.sh
- Follow the installation script for Docker:
-
Verify Docker Installation
- Check Docker version:
docker -v
- Check Docker version:
-
Install SonarQube
- Follow the installation script for SonarQube:
wget https://github.com/Hafeezbaig/tools_installation_scripts/raw/main/sonarqube.sh chmod +x sonarqube.sh ./sonarqube.sh
- Follow the installation script for SonarQube:
-
Start SonarQube Container
- Start the container if it's not running:
docker ps -a docker start <containerID>
- Start the container if it's not running:
-
Login to SonarQube Dashboard
- Username: admin
- Password: admin
-
Create SonarQube Token
- Navigate to Administration -> My Account -> Security -> Create token.
-
Integrate SonarQube with Jenkins
- Go to SonarQube Dashboard -> Administration -> Configuration -> Webhooks.
- Add the following URL:
http://<EC2_IP>:8080/sonarqube-webhook/
- Install Maven
- Follow the installation script for Maven:
wget https://github.com/Hafeezbaig/tools_installation_scripts/raw/main/Maven.sh chmod +x Maven.sh ./Maven.sh
- Follow the installation script for Maven:
- Install TRIVY
- Follow the installation script for TRIVY:
wget https://github.com/Hafeezbaig/tools_installation_scripts/raw/main/trivy.sh chmod +x trivy.sh ./trivy.sh
- Follow the installation script for TRIVY:
- Add SonarQube Server
- Navigate to Manage Jenkins -> Configure System -> SonarQube Servers.
- Add SonarQube URL and token.
- Add Docker Hub Credentials
- Navigate to Manage Jenkins -> Credentials -> System -> Global credentials.
- Add Docker Hub credentials with the ID
docker.
- Configure Shared Library
- Go to Manage Jenkins -> Configure System -> Global Pipeline Libraries.
- Add the following data:
- Name: my-shared-library
- Default Version: main
- Git URL:
https://github.com/Hafeezbaig/jenkins_shared_lib.git
- Check Pipeline Execution
- Monitor Jenkins logs for pipeline execution details.
- Review TRIVY scan results for Docker image vulnerabilities.
- Check the SonarQube dashboard for code quality reports.
Feel free to contribute to the project or use it as a reference for your own development needs. For any issues or suggestions, please open an issue in the GitHub repository.
This project is developed by Hafeez Baig.