How to Integrate Sonarqube with Jenkins in 2025?
# How to Integrate SonarQube with Jenkins in 2025
Integrating SonarQube with Jenkins enhances your CI/CD pipelines by providing automated code quality analysis.
In 2025, both Jenkins and SonarQube continue to be leading tools in the continuous integration landscape. This guide will walk you through the updated process of integrating these tools to ensure your code quality remains top-notch.
Prerequisites
Before beginning, ensure you have the following:
- Jenkins: A working Jenkins installation. If not, download and set it up from the official Jenkins site.
- SonarQube: An up-and-running SonarQube server. For setup, refer to their official guide.
- SonarQube Scanner: Installed on your Jenkins machine.
Step-by-Step Guide
Step 1: Configure SonarQube in Jenkins
-
Install the SonarQube Plugin:
- Navigate to
Manage Jenkins
>Manage Plugins
. - In the
Available
tab, search for "SonarQube Scanner" and install it.
- Navigate to
-
Configure SonarQube Servers:
- Go to
Manage Jenkins
>Configure System
. - Under
SonarQube Servers
, clickAdd SonarQube
. - Fill in the required details:
- Name: An identifier for the server.
- Server URL: The URL where your SonarQube instance is running. (Learn about setting up custom URLs here).
- Token: Use a token from a
SonarQube user account
with the appropriate permissions.
- Go to
Step 2: Setup Jenkins Job for SonarQube Analysis
-
Create or Configure a Jenkins Job:
- In Jenkins, click
New Item
or choose an existing job. - Under
Build Environment
, selectPrepare SonarQube Scanner environment
.
- In Jenkins, click
-
Add a SonarQube Scanner Execution:
- Add a build step
Execute SonarQube Scanner
. - Provide the necessary analysis properties such as
sonar.projectKey
,sonar.sources
,sonar.host.url
, etc.
- Add a build step
-
Customize Settings:
- If needed, disable specific filename rules as described in this guide on filename rules.
Step 3: Integrate in Pipeline
- Configure Pipeline Script:
- Use a pipeline script to incorporate SonarQube as a stage. Below is a basic setup:
pipeline { agent any stages { stage('SCM Checkout') { steps { checkout scm } } stage('SonarQube analysis') { environment { scannerHome = tool 'SonarQube Scanner' } steps { script { def sonarHome = tool 'SonarQube Scanner' withSonarQubeEnv('Your SonarQube Server Name') { sh "${sonarHome}/bin/sonar-scanner" } } } } } }
- Use a pipeline script to incorporate SonarQube as a stage. Below is a basic setup:
Step 4: Review and Analyze
-
Post Build Action:
- Include
Quality Gates
in Jenkins to monitor code quality through the build's status.
- Include
-
Explore Reports:
- Post-integration, navigate through the SonarQube dashboard to interpret code quality insights and take informed actions.
Additional Resources
- For detailed insights on CI integration, refer to this comprehensive guide.
- Customize your Jenkins and SonarQube integration further by exploring advanced configurations and plugins.
By following the steps above, you’ll have successfully integrated SonarQube with Jenkins in your CI/CD workflow for the year 2025, ensuring enhanced code quality and robust software delivery.