SonarQube intergration

step 1:

Signup and SetUp – SonarQube Cloud account using GitHub Objective: In this lab, you will signup SonarQube Cloud account using GitHub Creating a SonarQube Cloud account using GitHub 1.

Go to SonarQube cloud website

Authorize sonalcloud


3. go to and fork below project

4. Go to sonar cloud and import the orgnization

5. select repo

6. install

7. Note down the project key

8. create organization




10. get token

generate the token and note it down

12. Get the project key [click on my project–>click on sample-java-sonar

Left hand side select the icon

note down the project key


12. Prior to performing a Sonar scan through Jenkins, it is necessary to deactivate the automatic
analysis option in the SonarQube web graphical user interface (GUI). a. Go to SonarQube Web GUI
and click on “Administration” → “Analysis Method

13. setup quality gate

create new quality gate

Add condition

set default

modify the sudoers file in ubuntu

vi /etc/sudoers


Write the pipeline

pipeline {
agent any

stages {
stage('chckout scm') {
steps {
checkout scmGit(branches: [[name: '*/main']], extensions: [], userRemoteConfigs: [[url: '']])
stage('Compiling and Running Test Cases') {
steps {
sh 'mvn clean'
sh 'mvn compile'
sh 'mvn test'
stage('Generating a Cucumber Reports') {
steps {
script {
// Run Cucumber tests and generate reports
sh 'mvn verify'
stage('Creating Package') {
steps {
sh 'mvn package'
stage('adding genrerate report'){
steps {
sh 'mvn verify'
stage('Install sonarqube cli') {
steps {
// Step to install SonarQube CLI
sh 'wget -O'
sh 'unzip -o -q'
sh 'rm -rf /opt/sonar-scanner'
sh 'sudo mv --force sonar-scanner- /opt/sonar-scanner'
sh 'sudo sh -c \'echo "#/bin/bash \nexport PATH=\\\"$PATH:/opt/sonar-scanner/bin\\\"" >/etc/profile.d/\''
sh 'sudo chmod +x /opt/sonar-scanner/bin/sonar-scanner'
sh '. /etc/profile.d/'

stage('Analyzing Code Quality') {
steps {
// Step to analyze code quality with SonarQube
sh '/opt/sonar-scanner/bin/sonar-scanner -Dsonar.projectKey=owtest23_sample-java-sonar -Dsonar.organization=owtest23 -Dsonar.qualitygate.wait=true -Dsonar.qualitygate.timeout=300 -Dsonar.sources=src/main/java/ -Dsonar.login=65558d8b45ebd4758f3e8d49b8f3582f8707306'

In case it is failing remove the stage due to permission issue, remove stage “Install sonarqube cli” and step. Perform all the step manually on ubuntu server

wget -O

unzip -o -q

rm -rf /opt/sonar-scanner

mv --force sonar-scanner- /opt/sonar-scanner

export PATH="/opt/sonar-scanner/bin"

chmod +x /opt/sonar-scanner/bin/sonar-scanner