.net 未经授权:由于凭据无效,访问被拒绝,请检查SonarQube SonarScanner.MsBuild.exe中的身份验证参数

nwlls2ji  于 12个月前  发布在  .NET
关注(0)|答案(2)|浏览(194)

我正在尝试设置一个测试环境来测试SonarQube。这是我到目前为止采取的步骤:

  • 已下载并安装SonarQube。我可以运行它,导航到http://localhost:9000
  • 在Azure DevOps中为存储库创建了一个新项目。声纳能够连接到它,读取存储库等。
  • 下载最新版本的SonarScanner.MsBuild runner。解压缩并将路径放入%PATH%环境变量中
  • 在sonar中,我创建了一个新的User Token,并从runner文件夹中放入SonarQube.Analysis.xml
<Property Name="sonar.host.url">http://localhost:9000</Property>
<Property Name="sonar.login">admin</Property>
<Property Name="sonar.password">sonar</Property>
<Property Name="sonar.token">squ_7b.......601</Property>
  • 回到声纳,我创建了一个新的本地运行。
  • 选择Generate a project token选项并单击Next
  • 然后Sonar要求我运行以下命令:

SonarScanner.MSBuild.exe begin /k:"TEST_PROJECT-local" /d:sonar.host.url="http://localhost:9000" /d:sonar.token="sqp_ec60....a7e1"
我可以看到项目令牌是由Sonar创建的。但是当我运行它时,我得到以下错误:

SonarScanner for MSBuild 5.13
Using the .NET Framework version of the Scanner for MSBuild
Pre-processing started.
Preparing working directories...
09:15:30.629  Updating build integration targets...
09:15:30.797  Unauthorized: Access is denied due to invalid credentials. Please check the authentication parameters.
09:15:30.8  Pre-processing failed. Exit code: 1

我错过了什么?

xwbd5t1u

xwbd5t1u1#

尝试删除这两行

<Property Name="sonar.login">admin</Property>
<Property Name="sonar.password">sonar</Property>

从你的SonarQube.Analysis.xml文件。
我也遇到了同样的问题,并通过这样做来解决它。我认为这个问题与扫描仪试图使用登录名和密码有关,但如果列出了令牌,您真的应该使用它来进行身份验证。

a5g8bdjr

a5g8bdjr2#

我遇到了类似的问题,在日志中看到了以下内容:

SonarScanner for MSBuild 4.8
Using the .NET Framework version of the Scanner for MSBuild
Post-processing started.
12:44:09.281  12:44:09.281  This setting is not valid in the "end" phase in this version of the C# plugin: sonar.token
12:44:09.297  Post-processing failed. Exit code: 1
WARN: Unable to locate 'report-task.txt' in the workspace. Did the SonarScanner succeed?
ERROR: Execution of SonarScanner for MSBuild failed (exit code 1)

11:57:59.239  Failed to request and parse 'http://sonarqube.redacted.com/api/settings/values?component=SoftwareName': The remote server returned an error: (401) Unauthorized.
11:57:59.239  Could not authorize while connecting to the SonarQube server. Check your credentials and try again.
11:57:59.254  Pre-processing failed. Exit code: 1
ERROR: Execution of SonarScanner for MSBuild failed (exit code 1)

并在wireshark跟踪中看到以下内容:

3051    222.906323  HTTP    187 GET /api/settings/values?component=SoftwareName HTTP/1.1 
3052    222.909389  HTTP    840 HTTP/1.1 401

根本原因是Jenkins“工具”没有更新。我能够删除工具,然后它们自动重新安装到最新版本。由于此Jenkins安装在Windows上运行,因此我们删除了此文件夹:C:\Program Files(x86)\Jenkins\Tools\哈德逊.plugins.sonar. MsBuildSQRunner安装

参考:https://www.jenkins.io/doc/book/managing/tools/
https://docs.sonarsource.com/sonarqube/latest/analyzing-source-code/ci-integration/jenkins-integration/
https://docs.sonarsource.com/sonarqube/latest/analyzing-source-code/scanners/jenkins-extension-sonarqube/

相关问题