jenkins整合SonarQube

准备

  1. jenkins(ver 2.89.2)安装
  2. sonarQube(ver 6.7.2)安装
  3. sonar-scanner(ver 2.8)安装
  4. jenkins中安装SonarQube Plugin插件

配置sonar server

Jenkins–》系统设置–》SonarQube servers 
jenkins整合SonarQube_第1张图片

这里,sonarqube本地安装的是6.7.2的版本,为了登陆的时候可以选择账号、密码的方式方便进行整合,这里配置设置Server version为设置为5.3 or higher

必须使用sonarQube account token进行连接,这个更安全。 

Server authentication token项需要在sonar server端生成 
访问sonar server端 
菜单–》配置–》权限–》用户–》TOKENS–》Generate 生成token,将生成token添加到此处,完成添加。 

jenkins整合SonarQube_第2张图片


配置sonarqube,关闭经用SCM传感器配置为是,这一步操作完毕,jenkins才能真正使用sonarqube Server服务器,否则,否则质量分析时会出错

jenkins整合SonarQube_第3张图片


配置sonar scanner

系统管理–》Global Tool Configuration 
jenkins整合SonarQube_第4张图片

配置项目

要让jenkins编译完成,自动将代码传给sonarqube进行分析,则要配置jenkins中的目标项目。 

选择自己的project–》配置–》

jenkins整合SonarQube_第5张图片


SonarQube Scanner配置可以直接在项目根目录中创建一个文件(sonar-project.properties),然后使用path to project properties中指定属性文件,或者直接在Analysis Properties中书写

sonar-project.properties示例:

# must be unique in a given SonarQube instance
sonar.projectKey=management_test
# this is the name displayed in the SonarQube UI
sonar.projectName=management_test
sonar.projectVersion=1.0
 
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
# Since SonarQube 4.2, this property is optional if sonar.modules is set. 
# If not set, SonarQube starts looking for source code from the directory containing 
# the sonar-project.properties file.
sonar.sources=management_test/src
 
# Encoding of the source code. Default is default system encoding
sonar.sourceEncoding=UTF-8
# Additional parameters  
sonar.my.property=value  
sonar.java.binaries=management_test/target/classes


你可能感兴趣的:(sonar)