Integrate sonar in jenkins, use findbug, pmd, checkstyle to improve code quality

   In fact, jenkins can install these plugins alone, but it is not as professional as sonar, which focuses on integrating code quality inspection plugins, so perfectionists need to install a sonar separately.



    Sonar's full name, sonarqube, like jenkins, is a separate web server with a browser-based control interface. After it needs to be installed separately, it can be called remotely through the sonar scanner runner in jenkins.

    The installation process of sonarqube is relatively simple. A database it supports and a corresponding version of jdk can run with simple configuration, and then install the findbugs, PMD, checkstyle plug-ins in the sonarqube console, and Chinese language for Chinese users. Package plugin, a complete sonar server is set up.

    It should be noted that the official documentation of sonaqube does not indicate that the jdk version used by jenkins needs to be the same as the jdk version used by jenkins. The version of the jenkins plug-in sonar scanner runner should also match the version of the sonarqube server. If it does not match, it will be There are all kinds of Qiba problems, so you can't tear up your sister.

   start installation!

   Download sonarqube, download address , and download the sonarqube that is consistent with your jenkins jdk version. For jenkins using jdk1.7, download sonarqube5.5.

   Unzip it to the /opt/ directory, so the directory of sonarquber is /opt/sonarqube5.5, and modify the configuration file in this directory:
#conf/sonar.properties
#Modify the following lines
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar、

#Remove the comment of the mysql database url, we use the mysql database
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance

#If your server can't climb outside the wall to update the plug-in, you can configure an http proxy here
#I encountered such a problem, and it is very fast to configure an agent.
#http.proxyHost=
#http.proxyPort=


    After the configuration is complete, you need to create a mysql database. The database is created as follows:

#Create database sonar
create database sonar default charset utf8 COLLATE utf8_general_ci;

#Create database user sonar, password sonar
create user  sonar   IDENTIFIED by 'sonar';  

#Grant permissions to the sonar user
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE on sonar.*  to sonar@'%';
flush  privileges ;



    Well, everything is ready, just start. Before starting, make sure that your 9000 port is not occupied by other applications, and execute the start command:
#The current directory is /opt/sonarqube5.5, different operating systems choose different startup scripts
./bin/linux-x86-64/sonar.sh start

    Open the url http://192.168.1.23:9000 , secretly record the user name admin, password admin, see the login interface below, you are successful, one third.


    Next, configure the plug-ins. After the sonarqube is successfully logged in, click administration-->system-->update center-->available on the console interface, and the plug-ins that can be installed will be displayed



. To be continued...

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327036646&siteId=291194637