

持续集成实战三——持续代码质量管理Sonar部署
source link: https://chegva.com/1192.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

持续集成实战三——持续代码质量管理Sonar部署
持续代码质量管理Sonar部署实践
1 Sonar简介及部署
Sonar 是一个用于代码质量管理的开放平台。通过插件机制,Sonar 可以集成不同的测试工具,代码分析工具,以及持续集成工具。与持续集成工具(例如 Hudson/Jenkins 等)不同,Sonar 并不是简单地把不同的代码检查工具结果(例如 FindBugs,PMD 等)直接显示在 Web 页面上,而是通过不同的插件对这些结果进行再加工处理,通过量化的方式度量代码质量的变化,从而可以方便地对不同规模和种类的工程进行代码质量管理。
在对其他工具的支持方面,Sonar 不仅提供了对 IDE 的支持,可以在 Eclipse 和 IntelliJ IDEA 这些工具里联机查看结果;同时 Sonar 还对大量的持续集成工具提供了接口支持,可以很方便地在持续集成中使用 Sonar。
此外,Sonar 的插件还可以对 Java 以外的其他编程语言提供支持,对国际化以及报告文档化也有良好的支持。
2 Sonar实用操作
启动Sonar,登陆密码默认为admin/admin
[root@linux-node1 ~]# /usr/local/sonarqube/bin/linux-x86-64/sonar.sh start
Starting SonarQube...
Started SonarQube.
2 Sonar代码分析
2.1 Sonar代码分析原理
通过下载语言jar包插件,使用扫描器Sonar Scanner扫描器来实现代码扫描
[root@linux-node1 src]# unzip sonar-scanner-2.6.1.zip #解压下载好的扫描器 [root@linux-node1 src]# mv sonar-scanner-2.6.1 /usr/local/ [root@linux-node1 src]# ln -s /usr/local/sonar-scanner-2.6.1/ /usr/local/sonar-scanner
2.2 配置Sonar Scanner扫描器关联
[root@linux-node1 /usr/local/sonar-scanner/conf]# grep ^[a-z] sonar-scanner.properties sonar.host.url=http://localhost:9000 sonar.sourceEncoding=UTF-8 sonar.jdbc.username=sonar sonar.jdbc.password=sonar sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8
2.3 下载官方语言代码测试包进行测试
[root@linux-node1 ~]# cd sonar-examples-master/projects/languages/php/ #进入php语言的测试目录 [root@linux-node1 ~/sonar-examples-master/projects/languages/php]# ll total 0 drwxr-xr-x 4 root root 97 Oct 4 03:10 php-sonar-runner drwxr-xr-x 5 root root 89 Aug 14 02:12 php-sonar-runner-unit-tests [root@linux-node1 ~/sonar-examples-master/projects/languages/php]# cd php-sonar-runner [root@linux-node1 ~/sonar-examples-master/projects/languages/php/php-sonar-runner]# ll total 12 -rw-r--r-- 1 root root 453 Aug 14 02:12 README.md #测试使用说明 -rw-r--r-- 1 root root 331 Aug 14 02:12 sonar-project.properties #测试定义文件,没有不能测 drwxr-xr-x 2 root root 21 Aug 14 02:12 src #测试源码包 -rw-r--r-- 1 root root 272 Aug 14 02:12 validation.txt #在当前目录下调用扫描器文件执行测试 [root@linux-node1 ~/sonar-examples-master/projects/languages/php/php-sonar-runner]# /usr/local/sonar-scanner/bin/sonar-scanner INFO: Scanner configuration file: /usr/local/sonar-scanner/conf/sonar-scanner.properties INFO: Project root configuration file: /root/sonar-examples-master/projects/languages/php/php-sonar-runner/sonar-project.properties INFO: SonarQube Scanner 2.6.1 INFO: Java 1.8.0_101 Oracle Corporation (64-bit) INFO: Linux 3.10.0-327.18.2.el7.x86_64 amd64 INFO: User cache: /root/.sonar/cache INFO: Load global repositories INFO: Load global repositories (done) | time=176ms
再用java语言同样操作一次,可在web端查看报告
3 最终效果图,可以自定义仪表盘显示关注的信息

Recommend
-
89
-
68
通过 SonarQube 搭建代码质量管理平台(一) 的介绍,如果每次都需要手动执行 sonar-scanner ,想想也是醉了,所以我们需要进一步完善 SonarQube 进行自动化代码分析。 ...
-
50
-
52
导语: 随着业务的增长和开发团队的成员快速增加,其中很多新人来自于五湖四海各大门派,在编码的风格和习惯中也出现各异。 通常在相互 codereview 时发现很多代码上的问题,久而久之代码出现了代码难以维护的问题,甚至还会出现低级错误。 因此,我尝试在前端代码
-
50
## 一、Sonar 概述Sonar 是一个用于代码质量管理的开放平台。通过插件机制,Sonar 可以集成不同的测试工具,代码分析性工具,以及持续集成工具。与持续集成工具(例如 Hudson/Jenkins 等)不同,Sonar 并不是简单地把不同的代码检查工具结果(例如 FindBugs,PMD...
-
8
sonar代码质量分析相关 – ruquan.z – github技术博客,成长在于积累。 ruquan.z github技术博客,成长在于积累。
-
19
代码质量管理:SonarQube + Jenkins Pipeline配置
-
7
持续集成实战四——Jenkins集成Sonar进行代码质量管理 | CHEGVACHEGVA让我们面对现实 让我们忠于理想 ☘ 随机文章☯ 传统文化☺ 近期评论⌚ 博客统...
-
5
代码质量管理平台搭建 sonar简介 sonar是一款静态代码质量分析工具,支持Java、Python、PHP、JavaScript、CSS等25种以上的语言,而且能够集成在IDE、Jenkins、Git等服务中,方便随时查看代码质量分析报告; sonar通过配置的代码分...
-
8
Jenkins Sonar Github 代码质量管理 March 20, 2019 in sonarqube
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK