How to integrate SonarQube with Jenkins
Jenkins is a continuous integration tool which used to build and deploy applications. SonarQube is a Java based, open-source static code analysis tool. So, in this tutorial we are going to integrate SonarQube with Jenkins.
Prerequisites
Create SonarQube Token
You need to login to SonarQube by giving your username and password. Then click on My Account->Security then under Tokens click on Create Token and give a name to the token. Then click on Generate button and copy the created token
Install SonaQube Plugin
Login to your Jenkins server
Go to Manage Jenkins tab
Then click on Manage Plugins
Then select Available section and search for SonarQube Scanner for Jenkins plugin
Configure SonaQube Plugin
Go to Manage Jenkins tab
Then click on Configure System
Then SonarQube servers section, check on Environment variables
Then add SonarQube as Name and YOUR_SONARQUBE_URL:9000 as Server URL and for Server authentication token add YOUR_SONARQUBE_TOKEN which we created earlier
Then click on Save button
Now we have finished up with our configuration. Now we need to create pipeline to check our configuration
Jenkins Pipeline with SonarQube
Create a new pipeline job in Jenkins and for pipeline script section, use the following code:
1 | pipeline { |
Then run the pipeline