jenkins服务器部署扫描器 sonar-scanner
官方文档:https://docs.sonarqube.org/latest/analysis/scan/sonarscanner/
部署sonar-scanner
sonarqube通过调用扫描器sonar-scanner进行代码质量分析,即扫描器的具体工作就是扫描代码:
下载地址:https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/
下载较新的版本
[root@jenkins-ubuntu ~]#cd /usr/local/src
[root@jenkins-ubuntu src]#wget https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.3.0.2102-linux.zip
[root@jenkins-ubuntu src]#unzip sonar-scanner-cli-4.3.0.2102-linux.zip
[root@jenkins-ubuntu src]#ln -s /usr/local/src/sonar-scanner-4.3.0.2102-linux/ /usr/local/sonar-scanner
[root@jenkins-ubuntu ~]#vim /usr/local/sonar-scanner/conf/sonar-scanner.properties
#指向sonarqube服务器的地址
sonar.host.url=http://10.0.0.103:9000
sonar.sourceEncoding=UTF-8
准备测试代码
[root@jenkins-ubuntu ~]#unzip sonar-examples-master.zip
[root@jenkins-ubuntu ~]# cd sonar-examples-master/projects/languages/php/php-sonar-runner
[root@jenkins-ubuntu php-sonar-runner]#pwd
/root/sonar-examples-master/projects/languages/php/php-sonar-runner
[root@jenkins-ubuntu php-sonar-runner]#ll
total 28
drwxr-xr-x 4 root root 4096 Mar 14 12:06 ./
drwxr-xr-x 4 root root 4096 Jul 25 2016 ../
-rw-r--r-- 1 root root 453 Jul 25 2016 README.md
drwxr-xr-x 2 root root 4096 Mar 14 12:07 .scannerwork/
-rw-r--r-- 1 root root 331 Jul 25 2016 sonar-project.properties
drwxr-xr-x 2 root root 4096 Jul 25 2016 src/
-rw-r--r-- 1 root root 272 Jul 25 2016 validation.txt
[root@jenkins-ubuntu php-sonar-runner]#cat sonar-project.properties #以下为默认生成的配置文件
# Required metadata
sonar.projectKey=org.sonarqube:php-simple-sq-scanner #自定义项目key
sonar.projectName=PHP :: Simple Project :: SonarQube Scanner #项目名称,会显示在web
sonar.projectVersion=1.0 #项目版本
# Comma-separated paths to directories with sources (required)
sonar.sources=src #源代码目录
# Language
sonar.language=php #代码语言类型
# Encoding of the source files
sonar.sourceEncoding=UTF-8 #编码格式
在源代码目录执行扫描
手动在当前项目代码目录执行扫描,以下是扫描过程的提示信息,扫描的配置文件sonar-project.propertie每个项目都要有
[root@jenkins-ubuntu php-sonar-runner]#pwd
/root/sonar-examples-master/projects/languages/php/php-sonar-runner
[root@jenkins-ubuntu php-sonar-runner]#/usr/local/sonar-scanner/bin/sonar-scanner
#在源码所有目录下执行上面命令,可以看到如下显示
sonarquebe we界面验证扫描结果
可以查看到重新的代码块
本文链接:http://www.yunweipai.com/35896.html
原创文章,作者:kepupublish,如若转载,请注明出处:https://blog.ytso.com/52617.html