16

我有带有默认配置的 sonarqube 6.5。当 sonar.forceAuthentication 标志设置为 false 时,我可以通过下面给出的命令创建和分析项目。

mvn sonar:sonar -Dsonar.host.url=https://mySonarHost/sonar -Dsonar.login=mySonarUserKey

当我启用 sonar.forceAuthentication 参数 (sonar.forceAuthentication=true) 时,我无法分析项目。我总是得到 Maven 错误:

[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.3.0.603:sonar (default-cli) on project storm: Not authorized. Please check the properties sonar.login and sonar.password. -> [Help 1]

它不适用于默认管理员帐户或创建的用户帐户(具有分析项目的权限)。我也尝试过不使用用户密钥,而是使用用户的登录名和密码(-Dsonar.login以及-Dsonar.password在 Maven 配置中),但它也不起作用。我尝试使用不同的声纳版本(从 4.5.7、5.6.6 到最新的 6.5,但我总是得到相同的结果)。

在连接期间,我的 access.log 中有这样的消息:

IP_ADDRESS - - [08/Sep/2017:12:03:33 +0200] "GET /sonar/batch/index HTTP/1.1" 200 - "-" "ScannerMaven/3.3.0.603/3.5.0" "SOME_KEY"
IP_ADDRESS - - [08/Sep/2017:12:03:33 +0200] "GET /sonar/api/settings/values.protobuf HTTP/1.1" 401 - "-" "ScannerMaven/3.3.0.603/3.5.0" "SOME_KEY"

我需要将 sonar.forceAuthentication 参数设置为 true(只有受信任的用户才能访问它)。

知道如何通过带有凭据参数的 Maven 配置和访问 sonarqube 吗?

4

3 回答 3

15

您是否同时设置了sonar.login参数sonar.passwordhttps://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+Maven#AnalyzingwithSonarQubeScannerforMaven-Security)?

请注意,在最近的版本(如 SonarQube 6.5)中,您应该使用用户令牌并在sonar.login参数中设置它:https ://docs.sonarqube.org/display/SONAR/User+Token

于 2017-09-08T10:45:53.740 回答
9

这是我用来为我的项目更新 Sonar Cube Dashboard 的最小命令,

mvn clean install  sonar:sonar -Dsonar.host.url=<Server_URL> -Dsonar.login=<Token_For_Your_User_Id> -Dsonar.projectKey=<It will be calculated by default using group id & artifact id but its advisable that you use a unique string for all users> -Dsonar.projectName=<Descriptive Project Name to show on dashboard> -Dsonar.projectVersion=<if you wish to specify a version number>

如果字符串中包含空格,则始终可以将字符串值括在双引号中。

在使用上述命令之前,您需要为 Eric 提供的答案中指定的用户 ID 生成令牌。无需传递密码属性。

于 2018-07-12T13:38:26.590 回答
0

我在 -D 之后添加了一个空格,一切都很好!

于 2022-02-23T06:15:48.180 回答