参考:http://blog.csdn.net/wh211212...mysql
参考:http://blog.csdn.net/wh211212...nginx
SonarQube 登陆web
用户密码为安装sonar设置的用户名和密码sql
登陆到sonar平台,设置 administration -security -user -administrator (右键,从新获取一个tokens,名字自定义)api
右键复制 获取的tokens,而后去jenkins里面配置 sonar服务器
jenkins登陆 -> configure system -> SonarQube serversmaven
注:笔者安装的服务统一使用域名的方式访问。若是有须要,记得本地设置hoststhis
配置mavenurl
编辑位于$ MAVEN_HOME / conf或〜/ .m2中的settings.xml文件,设置插件前缀和可选的SonarQube服务器URL
<settings> <pluginGroups> <pluginGroup>org.sonarsource.scanner.maven</pluginGroup> </pluginGroups> <profiles> <profile> <id>sonar</id> <activation> <activeByDefault>true</activeByDefault> </activation> <properties> <!-- Optional URL to server. Default value is http://localhost:9000 --> <sonar.host.url> http://sonar.aniu.so # 填写本身的sonar服务器地址 </sonar.host.url> </properties> </profile> </profiles> </settings>
分析一个Maven项目
移动到一个maven项目目录内,执行下面命令
mvn clean verify sonar:sonar # 此段命令也能够在jenkins配置,以下:
mvn 分析完成以后,登陆sonar平台查看分析结果
从图中能够很明显的看出此项目存在347个BUG,而后给开发建立sonar帐号,让他们帮忙修复。。。
Sonargraph Integration: Skipping project aniu-api-product [tv.aniu:aniu-api-product], since no Sonargraph rules are activated in current SonarQube quality profile [SonarQube]
此报错暂时不影响maven 集成到 sonar上
413 Request Entity Too Large
缘由是nginx默认上传文件的大小是1M,可nginx的设置中修改
# 解决方法以下: 1.打开nginx配置文件 nginx.conf, 路径通常是:/etc/nginx/nginx.conf。 2.在http{}段中加入 client_max_body_size 20m; 20m为容许最大上传的大小(大小可自定义)。 3.保存后重启nginx,问题解决。
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%'; # 更改mysql 的max_allowed_packet参数,设置 max_allowed_packet = 64M ,而后重启mysql [mysqld] max_allowed_packet=32M https://dev.mysql.com/doc/refman/5.7/en/packet-too-large.html
注:这里报错能够经过查看sonar的web.log得出缘由。