Integrating SonarQube with Jenkins¶
Steps to Integrate¶
-
Install Plugins:
SonarQube Scannerplugin in Jenkins to publish the results to SonarQube Server. -
Add SonarQube Scanner:
Manage Jenkins > Tool, configure scanner.

- Configure SonarQube Server:
Manage Jenkins > System, add SonarQube server details.

- Best Practice: Use an access token (generated in SonarQube) instead of a
usernameandpassword. Save the token as aSecret TextunderCredentials.


- Configure Webhook: Set up a webhook in SonarQube Server to send analysis results to Jenkins.
- Read the official documentation here

Pipeline Stages¶
-
SonarQube Analysis
// This stage must be after "Testing" stage('SonarQube Analysis') { steps { dir('03.Projects/00.LocalOps/0.1.01-jar_Boardgame') { withSonarQubeEnv('sonar-server') { sh "$SCANNER_HOME/bin/sonar-scanner" } } } } -
Quality Gate Check
stage('Quality Gate') { steps { timeout(5) { waitForQualityGate abortPipeline: false } } }
For Python Projects¶
Add the following depencendies to your requirements.txt file:
sonar-scanner==4.6.2.2472
# For testing and code coverage
pytest==7.4.2
pytest-cov==4.1.0
coverage==7.3.1