1. 创建相关文件夹
mkdir -p /app/software
> # mkdir -p /app/software
2.上传文件
2.1. 上传文件
SonarScanner 安装包下载地址 将下列文件上传到 /app/software 文件夹中 (选择你需要使用的版本)
resources/SonarScanner/packages/sonar-scanner-cli-*-linux.zip
3. 安装 SonarScanner
3.1. 解压 SonarScanner
mkdir -p /app/midware/scanner
unzip -q /app/software/sonar-scanner-cli-*-linux.zip -d /app/midware/scanner
ln -s /app/midware/scanner/sonar-scanner-*-linux /app/midware/scanner/sonar_scanner_stable
> $ mkdir -p /app/midware/scanner
> $ unzip -q /app/software/sonar-scanner-cli-*-linux.zip -d /app/midware/scanner
> $ ln -s /app/midware/scanner/sonar-scanner-*-linux /app/midware/scanner/sonar_scanner_stable
3.2. 修改 settings.xml 配置文件
修改配置文件相关属性如下
sonar.host.url
--- SonarQube server 地址与端口号
#sonar.host.url=http://localhost:9000
改成 sonar.host.url=http://192.168.1.202:9000/sonarqube
vim /app/midware/scanner/sonar_scanner_stable/conf/sonar-scanner.properties
> $ vim /app/midware/scanner/sonar_scanner_stable/conf/sonar-scanner.properties
3.3. 配置 SonarScanner 环境变量
echo export SONAR_SCANNER_HOME=/app/midware/scanner/sonar_scanner_stable >> ~/.bash_profile
echo export PATH=\$SONAR_SCANNER_HOME/bin:\$PATH >> ~/.bash_profile
source ~/.bash_profile
sonar-scanner --version
> $ echo export SONAR_SCANNER_HOME=/app/midware/scanner/sonar_scanner_stable >> ~/.bash_profile
> $ echo export PATH=\$SONAR_SCANNER_HOME/bin:\$PATH >> ~/.bash_profile
> $ source ~/.bash_profile
> $ sonar-scanner --version
> INFO: Scanner configuration file: /app/midware/scanner/sonar-scanner-4.0.0.1744-linux/conf/sonar-scanner.properties
> INFO: Project root configuration file: NONE
> INFO: SonarQube Scanner 4.0.0.1744
> INFO: Java 11.0.3 AdoptOpenJDK (64-bit)
> INFO: Linux 3.10.0-862.el7.x86_64 amd64