码迷,mamicode.com
首页 > 其他好文 > 详细

SonarQube 系列之 — 02 补充&CI

时间:2020-06-23 00:37:17      阅读:90      评论:0      收藏:0      [点我收藏+]

标签:质量   nis   scanner   search   巴巴   配置   ini   instance   standard   

实践1. 集成阿里巴巴p3c规范

  1. 准备插件:
    找到SonarQube版本对应的p3c插件
    SonarQube7.6确认可用插件:https://github.com/caowenliang/sonar-pmd-p3c

  2. 下载插件代码并构建

>git clone https://github.com/caowenliang/sonar-pmd-p3c
>cd sonar-pmd-p3c
>mvn clean install -Dmaven.test.skip=true 
  1. 安装插件
    注意:由于sonar-pmd-p3c是在sonar-pmd-plugin基础上修改的。
    所以如果已安装原版本sonar-pmd-plugin,需要先删除原插件,并将构建好的插件sonar-pmd-plugin-3.2.1.jar放到SonarQube的插件目录extensions/plugins下
>rm -f /opt/sonarqube/extensions/plugins/sonar-pmd*
>cp sonar-pmd-p3c/target/sonar-pmd-plugin-3.2.1.jar /opt/sonarqube/extensions/plugins
  1. 重启SonarQube,在Quality Profiles【质量配置】页面点击Create:
    Name【名称】自己填
    Language【语言】选Java,点击Create按钮后,跳转到质量配置详情界面。

  2. 在详情界面,点击Activate more【更多激活规则】,在Search for rules...【搜索规则...】中搜索p3c,然后点击Bulk Change【批量修改】,确认Apply。
    技术图片

  3. 返回到Quality Profiles【质量配置】页面,将该质量配置Set as Default【设为默认】。
    技术图片

实践2. 集成到Jenkins

官方
0. 准备token
访问SonarQube,点击Administration -> Security,将 Force user authentication 设置为true。点击左上角用户头像 -> Security,生成token
技术图片

  1. 安装Sonar插件
    SonarQube Scanner Plugin
    技术图片

  2. 配置SonarQube服务
    进入Jenkins > 系统管理 > 系统设置 > SonarQube servers,点击Add SonarQube,
    check Enable injection of SonarQube server configuration as build environment variables
    name:自定义即可
    ServerUrl:sonar服务地址
    Server authentication token: 在sonar服务中生成的令牌token。注意:创建token时,需选择‘Secret Text‘认证.
    技术图片

  3. 配置 sonar-scanner,
    进入 Jenkins > 系统管理 > Global Tool Configuration > 找到 SonarQube Scanner,如图??
    技术图片

4.1 配置 Job(基于Maven的 Java项目为例)

Configure the project, and go to the Build Environment section.
Enable Prepare SonarScanner environment to allow the injection of SonarQube server values into this particular job. If multiple SonarQube instances are configured, you will be able to choose which one to use. Once the environment variables are available, use them in a standard Maven build step (Invoke top-level Maven targets) by setting the Goals to include, or a standard Gradle build step (Invoke Gradle script) by setting the Tasks to execute.

4.2 配置 Job(前端项目为例)
技术图片

3. SonarQube管理

3.1 账户权限配置

3.2 质量阀

SonarQube 系列之 — 02 补充&CI

标签:质量   nis   scanner   search   巴巴   配置   ini   instance   standard   

原文地址:https://www.cnblogs.com/liuyitan/p/13160755.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!