Jenkins + Maven + sonarqube build a code quality detection platform


Maven was analyzed using the sonarqube scanner

Install Jenkins

Install maven

Install sonarqube

Configure Jenkins + Maven + sonarqube

  • Sonarqube login

The user password is the user name and password set by the installation sonar

  • Log in to the sonar platform and set administration – Security – user – administrator (right click and get a token again. The name is customized)

Right click to copy the obtained tokens, and then go to Jenkins to configure sonar

  • Jenkins login – > configure system – > sonarqube servers

Note: the services installed by the author are accessed in the way of domain name. Remember to set hosts locally if necessary

  • Configure maven

Edit at $maven_ Home / conf or ~ / Settings in M2 XML file, set the plug-in prefix and optional sonarqube server URL

                <!-- Optional URL to server. Default value is http://localhost:9000 -->
         #Fill in your own sonar server address

Execute the Maven command to move to a directory

mvn clean verify sonar:sonar 
#This command can also be configured in Jenkins, as follows:

After the MVN analysis is completed, log in to the sonar platform to view the analysis results

It is obvious from the figure that there are 347 bugs in this project, and then create a sonar account for developers to help fix…

Relevant error reporting solution

  • Sonargraph Integration: Skipping project aniu-api-product [tv.aniu:aniu-api-product], since no Sonargraph rules are activated in current SonarQube quality profile [SonarQube]

This error will not affect Maven’s integration into sonar for the time being

  • 413 Request Entity Too Large

The reason is that the default upload file size of nginx is 1m, which can be modified in the settings of nginx

#The solution is as follows:

1. Open the nginx configuration file nginx Conf, the path is usually: / etc / nginx / nginx conf。
2. Add client in http {} segment_ max_ body_ size 20m;  20m is the maximum upload size allowed (the size can be customized).
3. Restart nginx after saving and solve the problem.
  • sonar Failed to upload report – 500: An error has occurred

Caused by: com.mysql.jdbc.PacketTooBigException: Packet for query is too large (22790518 > 16777216). You can change this value on the server by setting the max_allowed_packet’ variable.

show variables like '%max_allowed_packet%';
#Change MySQL Max_ allowed_ Packet parameter, set Max_ allowed_ Packet = 64M, then restart MySQL

Note: you can check sonar’s web Log to find out the reason.