1、jenkins工作目录的项目下添加sonar-project.properties文件,具体内容如下:
# must be unique in a given SonarQube instance
sonar.projectKey=seleniumdemo
# this is the name displayed in the SonarQube UI
sonar.projectName=seleniumdemo
sonar.projectVersion=1.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=src
# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8
#path to your project build output path
sonar.java.binaries=target/classes
2、进入项目的跟目录,执行sonar-scanner命令,报如下错:
INFO: User cache: /Users/yp-tc-m-2935/.sonar/cache
ERROR: SonarQube server [http://localhost:9000] can not be reached
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 2.061s
INFO: Final Memory: 4M/61M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarQube Scanner execution
ERROR: Unable to execute SonarQube
ERROR: Caused by: Fail to get bootstrap index from server
ERROR: Caused by: Failed to connect to localhost/0:0:0:0:0:0:0:1:9000
ERROR: Caused by: Connection refused (Connection refused)
ERROR:
ERROR: Re-run SonarQube Scanner using the -X switch to enable full debug logging.
解决方法:
sonarqube没有开启,启动sonarqube服务,不报此问题。
3、报错:
INFO: SonarQube Scanner 3.3.0.1492
INFO: Java 1.8.0_121 Oracle Corporation (64-bit)
INFO: Mac OS X 10.13.4 x86_64
INFO: User cache: /Users/yp-tc-m-2935/.sonar/cache
INFO: SonarQube server 7.8.0
INFO: Default locale: "zh_CN", source code encoding: "UTF-8"
WARN: SonarQube scanners will require Java 11+ starting on next version
INFO: Load global settings
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 4.057s
INFO: Final Memory: 4M/61M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarQube Scanner execution
ERROR: Not authorized. Analyzing this project requires to be authenticated. Please provide the values of the properties sonar.login and sonar.password.
ERROR:
ERROR: Re-run SonarQube Scanner using the -X switch to enable full debug logging.
经过几个小时的排查,他妈的是 sonar scanner的sonar-scanner.properties配置文件的某个key写成大写了。。