1. 1.4 SonarQube部署

1.1. 部署SonarQube

docker pull sonarqube:8.9.2-community
sysctl -w vm.max_map_count=262144
sysctl -w fs.file-max=65536
ulimit -n 65536
ulimit -u 4096
docker run -d --restart --name sonarqube -p 8082:9000 sonarqube:8.9.2-community

1.2. 使用Sonar Scanner进行分析

官方文档:https://docs.sonarqube.org/latest/analysis/overview/

安装Sonar Scanner

cd /usr/local/src/
wget https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.6.2.2472-linux.zip
unzip sonar-scanner-cli-4.6.2.2472-linux.zip
mv sonar-scanner-4.6.2.2472-linux/ /usr/local/
ln -s /usr/local/sonar-scanner-4.6.2.2472-linux/ /usr/local/sonar-scanner

配置Sonar Scanner

[root@linx-node2 ~]# vim /usr/local/sonar-scanner/conf/sonar-scanner.properties
sonar.host.url=http://localhost:9000
sonar.sourceEncoding=UTF-8

分析项目代码

如果你要使用Soanr Scanner分析一个项目代码,需要在项目的根路径下放置一个配置文件sonar-project.properties,这个配置文件用来描述本项目的相关信息,如项目名称,版本等。

例子如下:http://docs.sonarqube.org/display/SONAR/Analysis+Parameters

[root@linux-node3 ~]# vim sonar-project.properties
# must be unique in a given SonarQube instance
sonar.projectKey=devops-demo
# this is the name displayed in the SonarQube UI
sonar.projectName=devops-demo
sonar.projectVersion=2.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=.
sonar.java.binaries=.

# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8

开始进行代码质量分析

[root@linx-node2 ~]# /usr/local/sonar-scanner/bin/sonar-scanner
Copyright © 赵班长@新运维社区 2019 all right reserved,powered by Gitbook该文件修订时间: 2021-08-24 13:17:35

results matching ""

    No results matching ""