How to Integrate SonarQube with Jenkins?
Whats is SonarQube?
Sonar Qube is Your teammate for Code Quality and Security, it empowers all developers to write cleaner and safer code. Sonar Qube brings thousands of automated Static Code Analysis rules, protecting your app.
In the Traditional developing approach, Most IT companies follow a manual process for developing any system from build code to deploy code in the Production Server.
But here, Integrating with Jenkins and SonarQube can help developers assure their code quality, identify bugs, vulnerabilities, code smells, etc. (static code analysis) before building code automatically with Jenkins.
How to install SonarQube?
Pre-requisites
Install java 8 from the oracle website
https://www.oracle.com/technetwork/java/javase/downloads/index.html
Install Database from any of the below links
https://www.postgresql.org/ — PostgreSQL (8.x or 9.x)
https://www.microsoft.com/sqlserver/ — Microsoft SQL Server (2014 (MSSQL Server 12.0) or 2016 (MSSQL Server 13.0)
https://www.mysql.com/ — MySQL (5.6 or 5.7)
Jenkins Should be installed
Procedure
Step 1: Download SonarQube from https://www.sonarqube.org/downloads/
Step 2: unzip the downloaded file
# unzip filename.zip
if you don’t have zip installed on your Linux machine
# yum install unzip — on CentOS and Fedora
# apt install unzip — on Ubuntu and Debian
Note you should run the SonarQube from a specific user only, you should not run with the root user, because SonarQube also contains the ElasticSearch which will be in the SonarQube directory. So, basically, when you start SonarQube instance with root permissions it will generate an error in the start-up of ElasticSearch.
Before starting the server you have to set a database connection with sonar. And you can find it in sonar. properties in sonarqube/conf
Example for PostgreSQL
sonar.jdbc.username=sonarqube
sonar.jdbc.password=mypassword
sonar.jdbc.url=jdbc:postgresql://localhost/sonarqube
SonarQuber server will start on port 9000. You can alter it in sonar.properties file
sonar.web.port=9000
To start SonarQube Server from its directory /bin/SONARPATH
sh sonar.sh console
Integrate SonarQube with Jenkins
- Login into Jenkins and install the SonarQube scanner plugin
Go to Manage Jenkins –> Manage Plugins > Available –> SonarQube scanner - Configure SonarQube home path
Go to Manage Jenkins –> Global Tool Configuration –> SonarQube Scanner (Refer below image)
3. Configure sonar auth token…Log in into your SonarQube Server and find the following under the user bar and Go to My Account –> Security –> Generate Token
4. Go to Manage Jenkins –> Configure Systems –> SonarQube Servers
Add server authentication token as following
Select your new sonar credentials as server auth token
Save the configuration, Now, your SonarQube integration is completed with Jenkins, next you have to create your new Jenkins job with sonar stage, and publish your code quality details in SonarQube,
I will be writing a new post on creating a Jenkins pipeline with sonar code quality stage. Stay Tuned!
Hope you enjoyed my post Follow me on medium for more useful DevOps-related blogs, Thank you for reading!
Imp link: https://dailyscrawl.com/how-to-install-postgresql-on-amazon-linux-2/
Imp link: https://www.vultr.com/docs/how-to-install-sonarqube-on-centos-7