8)登录的用户名及密码均默认为admin
9)成功登录sonarqube的web页面
4.安装中文插件,显示为中文界面
1)点击administration→Marketplace,直接搜索中文插件
2)在点击安装install
3)重新启动服务
[sonarqube@sonarqube linux-x86-64]$ ./sonar.sh restart
4)再次访问时,显示中文界面
5)查看安装的中文包插件
[sonarqube@sonarqube sonarqube]$ ll extensions/plugins/
……
-rw-r--r-- 1 sonarqube sonarqube 38307 Jul 29 15:05 sonar-l10n-zh-plugin-1.19.jar
……
6)安装Python、java、php等开发语言插件,才能扫描相关语言代码
5.部署扫描器sonar-scanner(sonarqube通过扫描器扫描代码)
1)scanner二进制×××地址
https://binaries.sonarsource.com/Distribution/sonar-scanner-cli
2)下载扫描器到指定目录下
[root@sonarqube sonarscanner]# pwd
/apps/sonarscanner
[root@sonarqube sonarscanner]# ll -h
total 41M
-rw-r--r-- 1 root root 41M Jul 22 19:31 sonar-scanner-cli-4.0.0.1744-linux.zip
3)解压扫描器二进制源码并创建软连接
[root@sonarqube sonarscanner]# unzip sonar-scanner-cli-4.0.0.1744-linux.zip
[root@sonarqube sonarscanner]# ls
sonar-scanner-4.0.0.1744-linux sonar-scanner-cli-4.0.0.1744-linux.zip
[root@sonarqube sonarscanner]# ln -sv sonar-scanner-4.0.0.1744-linux sonar-scanner
‘sonar-scanner’ -> ‘sonar-scanner-4.0.0.1744-linux’
4)修改配置文件
[root@sonarqube sonar-scanner]# vim conf/sonar-scanner.properties
……
#----- Default SonarQube server
sonar.host.url=http://192.168.1.31:9000
#----- Default source code encoding
sonar.sourceEncoding=UTF-8
5)准备一个测试代码压缩包并解压到当前目录下
[root@sonarqube code-test]# pwd
/apps/code-test
[root@sonarqube code-test]# ll -h
total 6.5M
-rw-r--r-- 1 root root 6.5M Nov 21 2018 sonar-examples-master.zip
[root@sonarqube code-test]# unzip sonar-examples-master.zip
6)切换到测试源码的路径下
[root@sonarqube php-sonar-runner]# pwd
/apps/code-test/sonar-examples-master/projects/languages/php/php-sonar-runner
[root@sonarqube php-sonar-runner]# ll
total 12
-rw-r--r-- 1 root root 453 Jul 25 2016 README.md
-rw-r--r-- 1 root root 331 Jul 25 2016 sonar-project.properties
drwxr-xr-x 2 root root 22 Jul 25 2016 src
-rw-r--r-- 1 root root 272 Jul 25 2016 validation.txt
7)默认生成的代码配置文件
[root@sonarqube 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 #项目的名称
sonar.projectVersion=1.0 #项目的版本号
# Comma-separated paths to directories with sources (required)
sonar.sources=src #源码路径
# Language
sonar.language=php #源码的类型为PHP代码
# Encoding of the source files
sonar.sourceEncoding=UTF-8 #编码的格式
8)在当前的代码路径下执行扫描
[root@sonarqube php-sonar-runner]# /apps/sonarscanner/sonar-scanner/bin/sonar-scanner
……
tly specify it.
INFO: Calculating CPD for 1 file
INFO: CPD calculation finished
INFO: Analysis report generated in 213ms, dir size=34 KB
INFO: Analysis reports compressed in 42ms, zip size=10 KB
INFO: Analysis report uploaded in 3108ms
INFO: ANALYSIS SUCCESSFUL, you can browse :9000/dashboard/index/org.sonarqube:php-simple-sq-scanner
INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
INFO: More about the report processing at :9000/api/ce/task?id=AWw9AEUVHii-ILef0qYq
INFO: Task total time: 17.226 s
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
INFO: Total time: 29.467s
INFO: Final Memory: 7M/115M
INFO: ------------------------------------------------------------------------
9)web端查看扫描后生成的记录
部署SonarQube代码检测服务以及jenkins实现代码自动(2)
内容版权声明:除非注明,否则皆为本站原创文章。
转载注明出处:https://www.heiqu.com/0daa98b84cc47b06d9dcc560716cffd8.html