🚀 Comprehensive Guide to Setting Up SonarQube, Jenkins, Docker, and CI/CD Integration
Written by Sivaranjan
Output
Servers
SonarQube Setup 🛠️
SonarQube Server Installation
Install JDK:
sudo apt install openjdk-17-jre
Download Community Edition:
wget <sonarqube file link> ls
Install SonarQube:
sudo apt install unzip unzip sonar.zip cd sonarqube/bin/linux ./sonar.sh console
Add Inbound Rule:
- Open port
9000
for SonarQube.
- Open port
SonarQube Configuration
Access SonarQube GUI:
Visit
http://<your_ip>:9000
in your browser.Default credentials:
admin/admin
Set New Password.
Create Project:
- Fill in details: Name, Key, Branch (main).
Setup Project:
CI: Jenkins
Platform: GitHub
Build Description: Other
Copy Project Key
Generate Token:
- Navigate to
Admin User -> Security -> Generate Token
- Navigate to
Jenkins SonarQube Integration 🔗
Jenkins Server Setup
Install Java & Jenkins:
Create Free-Style Job:
Source: Git URL
Branch:
*/main
Build Trigger:
- GitHub webhook
Manage Plugins:
Install SonarQube Scanner
Install SSH2 Easy
Global Tool Configuration:
Go to SonarScanner
Name: Add and set to auto-install (version 4.8.0)
System Configuration:
Go to SonarQube Server settings
Name: Add SonarQube Server
URL: Add URL
Authenticate using Secret Text
Build Steps:
Execute SonarQube Scanner
Add Project Key in Analysis Properties
Verify SonarQube Scan:
Build the Jenkins job to check SonarQube scan results.
Docker Setup 🐳
Docker Server on Ubuntu
Install Docker:
Switch to Root:
sudo su
Configure SSH:
vi /etc/ssh/sshd_config
- Enable
PubkeyAuthentication
andPasswordAuthentication
- Enable
systemctl restart sshd
passwd ubuntu # Set new password
mkdir website # Create deployment path
Add User to Docker Group:
sudo usermod -aG docker ubuntu newgrp docker
Integrate Jenkins with Docker 🤝
Jenkins to Docker Server Integration
Switch User to Jenkins:
su jenkins
SSH to Docker Server:
ssh ubuntu@docker_ip
Generate SSH Key:
ssh-keygen
Copy SSH Key to Docker:
ssh-copy-id ubuntu@docker_ip
GitHub Setup 🐙
Create Webhook URL
Create a webhook in your GitHub repository to trigger Jenkins builds.
Jenkins Job for Docker Deployment 📦
Jenkins GUI Configuration
Add Docker Server Group:
Name: Docker server
SSH Port: 22
Username: ubuntu
Password: your password
Add Server List:
Server Group: Docker server
Server Name: docker
Server IP: docker_ip
Post-Build Action:
Select Remote Shell
Target Server: Docker
Shell Command:
touch hello.txt
Verify Deployment:
Check if
hello.txt
is created in Docker server:ls
Docker Deployment via Jenkins 🏗️
GitHub Configuration
Create Dockerfile in GitHub:
FROM nginx COPY . /usr/share/nginx/html
Jenkins GUI Configuration
Post-Build Action:
Remove Remote Shell
Execute SCP Command:
scp -r ./* ubuntu@docker_ip:/home/ubuntu/website
Add Remote Shell Action:
Target Server: Docker server
Shell Commands:
cd /home/ubuntu/website docker build -t mywebsite . docker run -itd -p 8085:80 --name onix mywebsite
Verify Deployment:
- Build the Jenkins job and check the deployment.
By following these steps, you can set up a comprehensive CI/CD pipeline integrating SonarQube, Jenkins, Docker, and GitHub. This guide ensures a streamlined process from code analysis to deployment, enhancing code quality and efficiency. Happy coding! 🚀