In my previous blogs I have covered about Jenkins and SonarQube where I have explained their features, installation and configuration. Now in this blog I will cover how you can configure SonarQube scanner in Jenkins so that before deploying the code you can scan it through SonarQube and stop the deployment process if the test is fail from SonarQube.
This way we can also ensure the code quality before deploying it to the server. So lets start the process of integrating SonarQube scanner in Jenkins.
Before staring this process please ensure that you have installed SonarQube and Jenkins on your machine. In case you have not installed them please refer to my previous blogs on SonarQube and Jenkins:
- Why SonarQube is important for IT projects ?
- SonarQube installation on Ubuntu
- Analyze your project with SonarQube
- Install Jenkins on Ubuntu
- Configure Jenkins for Automated Code Deployment
Use following steps for configuring SonarQube with Jenkins:
- Open Jenkins on your browser and login using the credentials.
- Click on 'Manage Jenkins' on left menu. This will open the Manage Jenkins page with different options.
- Click on 'Manage Plugins' option from the list.
- Now click on 'Available' tab to search for the plugin.
- Type 'SonarQube' in the filter text box and hit enter.
- From the list click on install button of 'SonarQube Scanner for Jenkins' plugin.
- This will install the SonarQube scanner plugin.
- Now go to project page and click on 'Configure' link from the left menu.
- Scroll down to the 'Execute SonarQube Scanner' section under build.
- You can enter the optional fields like task to run, JDK and path to project properties.
- Under analysis properties option add following code and change it as per your project configuration:
sonar.exclusions=vendor/**, storage/**, resources/**
If your SonarQube server is located on a different cluster then provide the SonarQube server location in the jenkins configuration:
Your SonarQube scanner integration has been done now build your project to check the SonarQube scan result under console output. Following screen shows the SonarQube result from Jenkins:
I hope this blog can help you to setup SonarQube scanner with Jenkins. In case of any doubt please leave a comment.
Author | Blogger | Tech Lead | Elastic Stack | Innovator |View Profile
Aug 28, 2018, 8:12:22 AM
If I have a Sonarqub?e installation on a cluster how do I tell jenkins where my Sonarqube installation is?
Sep 1, 2018, 1:24:44 PM
Hi Daniel for that you need to provide the SonarQube cluster URL during Jenkins configuration.
Sep 1, 2018, 1:29:15 PM
The setting which you need in the property file is:sonar.host.url=http://192.xxx.xx.xx:9000/sonar
Sep 9, 2018, 3:02:46 AM
How to setup https for sonarqube?
Sep 13, 2018, 8:25:39 PM
I have changed the sonar source and I encounter the below error.ERROR: Invalid value of sonar.sources for com.****.it.***:xyz I have used the file that I have in my Bitbucket. Am I missing something here?
Leave a comment
Mar 9, 2019, 8:20:38 AM | Anurag Srivastava
Feb 9, 2019, 6:34:22 PM | Anurag Srivastava
Jan 31, 2018, 6:11:29 AM | Anurag Srivastava
Apr 14, 2018, 1:18:05 PM | Anurag Srivastava
Feb 9, 2019, 12:06:18 PM | Anurag Srivastava
Jun 21, 2018, 4:58:11 AM | Anurag Srivastava
Jun 26, 2018, 4:50:18 PM | Anurag Srivastava
Jul 16, 2018, 5:00:02 PM | Anurag Srivastava
Jul 12, 2018, 7:40:51 PM | Anurag Srivastava
Aug 14, 2018, 4:47:56 PM | Anurag Srivastava