integrate sonarqube with jenkins

50 %
50 %
Information about integrate sonarqube with jenkins

Published on July 19, 2019

Author: linuxdady


slide 1: LinuxDady.Com How to integrate sonarqube with jenkins server For more information visit slide 2: How to Integrate sonarqube with jenkins In this tutorial we are going to learn how to integrate sonarqube with jenkins. But first we should aware about what is sonarqube and what it does Actually sonarqube is an open source tool that is used to check-up our code quality means it has sonarqube scanner in the backend that detect bugs code smells and security vulnerabilities in our code and display on sonarqube dashboard. Integrate sonarqube with jenkins Before integration of sonarqube with jenkins we should be ready with below prerequisites. Don’t try to use below this configuration otherwise it will show the error of jvm. So if possible install sonarqube on below hardware . RAM – 2GB CPU – 2 Core OS – Centos7/Rhel7 Pre-configured jenkins server Click Read:– How to install and setup jenkins server For sonarqube java version should be above version 1.8. So if you are using Rhel 7 you have to add extra repository but in case of Centos it is default. 1 2 3 4 yum -y install epel-release yum -y install java yum -y update shutdown -r now PostgreSQL database installation to integrate sonarqube with jenkins Sonarqube is using database to store report in the backend. Postgres is default database but we can use anyone like Mysql Oracle. But in my case I am using PostgreSQL. So let’s add repository of PostgreSQL. slide 3: 1 rpm -Uvh centos96-9.6-3.noarch.rpm We have successfully added our repository now let’s install our Postgres package with the help of yum. 1 yum -y install postgresql96-server postgresql96-contrib First time we have to initialize our Postgres database to read its configuration file. So run below command to initialize our database. 1 /usr/pgsql-9.6/bin/postgresql96-setup initdb Initialization process has been done properly now let go to configuration file of Postgres. 1 2 cd /var/lib/pgsql/9.6/data ls Default Postgres configuration file will look like below check it default parameter properly. Because we are going change some parameter. 1 vim pg_hba.conf slide 4: After change in configuration file hba.conf it will look like below. We have changed some security and remote connection parameters. Like ident – md5 and peer – trust . 1 vim pg_hba.conf We have to start service of PostgreSQL to reflect the changes. 1 2 3 systemctl start postgresql-9.6 systemctl enable postgresql-9.6 systemctl status postgresql-9.6 Login to PostgreSQL and create database and use for sonarqube Switch to the Postgres user because now we are going to create database for sonarqube. In this database our report will save. 1 2 3 4 su - postgres createuser sonar psql ALTER USER sonar WITH ENCRYPTED password ‘sonar321’ slide 5: create a database sonar and provide sonar database ownership to sonar user. After creating database kindly cross verify its properly created or not with \list command. 1 2 3 CREATE DATABASE sonar OWNER sonar \q exit Postgres database has been setup properly. Now let’s install sonarqube server but we have to download package of sonarqube. 1 2 3 4 cd /opt wget ls unzip slide 6: We are installing sonarqube version 6.4 for latest version visit its official website if required and then download. 1 Now let’s connect sonarqube server with database because sonarqube don’t know which one database we are using in the backend. So go to sonarqube configuration file and pass the detail of database. 1 2 3 cd /opt/sonarqube-6.4/conf/ ls vim Uncomment the PostgreSQL jdbc connector and fill our database user name and password as shown above fig. Start and check status of sonarqube service. 1 2 3 cd /opt/sonarqube-6.4/bin/linux-x86-64 ./ start ./ status slide 7: Go to your browser and open sonarqube URL It should be open. If facing any issue check firewall Selinux and log file of sonarqube what error is showing. 1 Default username and password of sonarqube dashboard is admin admin. Which is shown below image. L e t ’ s integrate sonarqube with jenkins Still we have installed and configured our sonarqube server properly. Now we are going to integrate sonarqube with jenkins server. So login to you jenkins server. In my case I am using separate remote machine for jenkins. At jenkins server first you have to install sonarqube scanner plugin. So go to –Manage jenkins– Plugins Manager and install the required plugin. slide 8: Plugin of sonarqube scanner has been installed but still sonarqube package installation is pending. So go to –Mange jenkins – Global Tool Configuration – Scroll down and search for sonarqube option select here version accordingly and click on – save Sonarqube scanner will automatically install in the backend. Our integration of sonarqube with jenkins has been done only one thing is pending our jenkins is don’t know where our sonarqube server is running. So we have to pass only sonarqube server details in jenkins. There are two way to pass sonarqube server details. 1. Create a user in jenkins and then create token for this user into sonarqube and then add that token into jenkins. 2. Second way is very simple just pass sonarqube server details in maven directly while making build. I am using second method. So is private IP of my AWS ec2 instance where I have installed sonarqube server. In your case might be differ so change according. And admin admin is default password of sonarqube server 1 install sonar:sonar -Dsonar.loginadmin - Dsonar.passwordadmin slide 9: Properly enter the sonarqube server detail in build option and cross verify user name and password of sonarqube server. Save all above setting properly and then start your build creation process like below. Click Read: – How to configure first jenkins jobs step by step Login to sonarqube database and check code inspect report If our build become success then go to sonarqube serve and refresh sonarqube dashboard. It will show output like below. If your output is not coming then there is something wrong. So go to jenkins build console output and check logs properly. slide 10: So we have simply integrated sonarqube with jenkins server properly. Just you have to send this report to your developer team. They will analyse this report and will take action accordingly. Conclusion Today we have learn how to integrate sonarqube with jenkins and it’s related parameters. So this is very important tool to inspect developer code continuously. Still if anyone have any query write me in comment box. I will try my best to resolve that query. Interview question of sonarqube ▪ What is default port of sonarqube ▪ What is quality gate ▪ What is sonarqube scanner ▪ What does sonarqube

Add a comment

Related presentations