Sonarqube C# MsBuild 访问被拒绝

Posted

技术标签:

【中文标题】Sonarqube C# MsBuild 访问被拒绝【英文标题】:Sonarqube C# MsBuild Access denied 【发布时间】:2018-07-14 07:49:19 【问题描述】:

我有一个使用 SonarC# (6.7.1) 的 Sonarqube (6.7.1) 服务器,由 Bitnami Google Cloud Platform 构建。

我按照教程进行操作: https://docs.sonarqube.org/display/SCAN/Scanning+on+Linux+or+macOS

创建了一个新的空项目“ConsoleApp1”

但是在最后一步: 单声道 ~/Tools/ScannerMSBuild/SonarQube.Scanner.MSBuild.exe 结束 /d:sonar.login=XYZ

会弹出异常:

Calling the SonarQube Scanner...

Unhandled Exception:
System.ComponentModel.Win32Exception (0x80004005): ApplicationName='/Users/magic/Documents/Projects/services/sonar-scanner-msbuild/sonar-scanner-3.0.3.778/bin/sonar-scanner', CommandLine='"-Dsonar.login=admin" "-Dsonar.scanAllFiles=true" "-Dsonar.password=xxxxxx" "-Dproject.settings=/Users/magic/Documents/Projects/c#/ConsoleApp1/.sonarqube/out/sonar-project.properties"', CurrentDirectory='/Users/magic/Documents/Projects/c#/ConsoleApp1', Native error= Access denied
  at System.Diagnostics.Process.StartWithCreateProcess (System.Diagnostics.ProcessStartInfo startInfo) [0x002dc] in <04fdc8acaa5e466bb267a3960bdb1f37>:0
  at System.Diagnostics.Process.Start () [0x0003a] in <04fdc8acaa5e466bb267a3960bdb1f37>:0
  at (wrapper remoting-invoke-with-check) System.Diagnostics.Process.Start()
  at SonarQube.Common.ProcessRunner.Execute (SonarQube.Common.ProcessRunnerArguments runnerArgs) [0x000df] in <184f94cfa81445e38fb1a98c6eca5c13>:0
  at SonarScanner.Shim.SonarScannerWrapper.ExecuteJavaRunner (SonarQube.Common.AnalysisConfig config, System.Collections.Generic.IEnumerable`1[T] userCmdLineArguments, SonarQube.Common.ILogger logger, System.String exeFileName, System.String propertiesFileName) [0x00053] in <40209c7fedb345b0bc4e48d7b04dc4cc>:0
  at SonarScanner.Shim.SonarScannerWrapper.InternalExecute (SonarQube.Common.AnalysisConfig config, System.Collections.Generic.IEnumerable`1[T] userCmdLineArguments, SonarQube.Common.ILogger logger, System.String fullPropertiesFilePath) [0x0001b] in <40209c7fedb345b0bc4e48d7b04dc4cc>:0
  at SonarScanner.Shim.SonarScannerWrapper+<>c__DisplayClass6_0.<Execute>b__0 () [0x0003a] in <40209c7fedb345b0bc4e48d7b04dc4cc>:0
  at SonarScanner.Shim.SonarProjectPropertiesValidator.Validate (System.String sonarScannerCwd, System.Collections.Generic.ICollection`1[T] projects, System.Action onValid, System.Action`1[T] onInvalid) [0x00082] in <40209c7fedb345b0bc4e48d7b04dc4cc>:0
  at SonarScanner.Shim.SonarScannerWrapper.Execute (SonarQube.Common.AnalysisConfig config, System.Collections.Generic.IEnumerable`1[T] userCmdLineArguments, SonarQube.Common.ILogger logger) [0x00092] in <40209c7fedb345b0bc4e48d7b04dc4cc>:0
  at SonarQube.TeamBuild.PostProcessor.MSBuildPostProcessor.InvokeSonarScanner (SonarQube.Common.IAnalysisPropertyProvider cmdLineArgs, SonarQube.Common.AnalysisConfig config) [0x00013] in <c02c645a99c24060a2edd0cf9161959e>:0
  at SonarQube.TeamBuild.PostProcessor.MSBuildPostProcessor.Execute (System.String[] args, SonarQube.Common.AnalysisConfig config, SonarQube.TeamBuild.Integration.Interfaces.ITeamBuildSettings settings) [0x000c3] in <c02c645a99c24060a2edd0cf9161959e>:0
  at SonarQube.Bootstrapper.BootstrapperClass.PostProcess () [0x00080] in <76e5086a486b4c68925b0809607fa8c1>:0
  at SonarQube.Bootstrapper.BootstrapperClass.Execute () [0x00041] in <76e5086a486b4c68925b0809607fa8c1>:0
  at SonarQube.Bootstrapper.Program.Execute (System.String[] args, SonarQube.Common.ILogger logger) [0x000dd] in <76e5086a486b4c68925b0809607fa8c1>:0
  at SonarQube.Bootstrapper.Program.Main (System.String[] args) [0x00021] in <76e5086a486b4c68925b0809607fa8c1>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.ComponentModel.Win32Exception (0x80004005): ApplicationName='/Users/magic/Documents/Projects/services/sonar-scanner-msbuild/sonar-scanner-3.0.3.778/bin/sonar-scanner', CommandLine='"-Dsonar.login=admin" "-Dsonar.scanAllFiles=true" "-Dsonar.password=xxxxxx" "-Dproject.settings=/Users/magic/Documents/Projects/c#/ConsoleApp1/.sonarqube/out/sonar-project.properties"', CurrentDirectory='/Users/magic/Documents/Projects/c#/ConsoleApp1', Native error= Access denied
  at System.Diagnostics.Process.StartWithCreateProcess (System.Diagnostics.ProcessStartInfo startInfo) [0x002dc] in <04fdc8acaa5e466bb267a3960bdb1f37>:0
  at System.Diagnostics.Process.Start () [0x0003a] in <04fdc8acaa5e466bb267a3960bdb1f37>:0
  at (wrapper remoting-invoke-with-check) System.Diagnostics.Process.Start()
  at SonarQube.Common.ProcessRunner.Execute (SonarQube.Common.ProcessRunnerArguments runnerArgs) [0x000df] in <184f94cfa81445e38fb1a98c6eca5c13>:0
  at SonarScanner.Shim.SonarScannerWrapper.ExecuteJavaRunner (SonarQube.Common.AnalysisConfig config, System.Collections.Generic.IEnumerable`1[T] userCmdLineArguments, SonarQube.Common.ILogger logger, System.String exeFileName, System.String propertiesFileName) [0x00053] in <40209c7fedb345b0bc4e48d7b04dc4cc>:0
  at SonarScanner.Shim.SonarScannerWrapper.InternalExecute (SonarQube.Common.AnalysisConfig config, System.Collections.Generic.IEnumerable`1[T] userCmdLineArguments, SonarQube.Common.ILogger logger, System.String fullPropertiesFilePath) [0x0001b] in <40209c7fedb345b0bc4e48d7b04dc4cc>:0
  at SonarScanner.Shim.SonarScannerWrapper+<>c__DisplayClass6_0.<Execute>b__0 () [0x0003a] in <40209c7fedb345b0bc4e48d7b04dc4cc>:0
  at SonarScanner.Shim.SonarProjectPropertiesValidator.Validate (System.String sonarScannerCwd, System.Collections.Generic.ICollection`1[T] projects, System.Action onValid, System.Action`1[T] onInvalid) [0x00082] in <40209c7fedb345b0bc4e48d7b04dc4cc>:0
  at SonarScanner.Shim.SonarScannerWrapper.Execute (SonarQube.Common.AnalysisConfig config, System.Collections.Generic.IEnumerable`1[T] userCmdLineArguments, SonarQube.Common.ILogger logger) [0x00092] in <40209c7fedb345b0bc4e48d7b04dc4cc>:0
  at SonarQube.TeamBuild.PostProcessor.MSBuildPostProcessor.InvokeSonarScanner (SonarQube.Common.IAnalysisPropertyProvider cmdLineArgs, SonarQube.Common.AnalysisConfig config) [0x00013] in <c02c645a99c24060a2edd0cf9161959e>:0
  at SonarQube.TeamBuild.PostProcessor.MSBuildPostProcessor.Execute (System.String[] args, SonarQube.Common.AnalysisConfig config, SonarQube.TeamBuild.Integration.Interfaces.ITeamBuildSettings settings) [0x000c3] in <c02c645a99c24060a2edd0cf9161959e>:0
  at SonarQube.Bootstrapper.BootstrapperClass.PostProcess () [0x00080] in <76e5086a486b4c68925b0809607fa8c1>:0
  at SonarQube.Bootstrapper.BootstrapperClass.Execute () [0x00041] in <76e5086a486b4c68925b0809607fa8c1>:0
  at SonarQube.Bootstrapper.Program.Execute (System.String[] args, SonarQube.Common.ILogger logger) [0x000dd] in <76e5086a486b4c68925b0809607fa8c1>:0
  at SonarQube.Bootstrapper.Program.Main (System.String[] args) [0x00021] in <76e5086a486b4c68925b0809607fa8c1>:0

有人知道如何解决这个问题吗?非常感谢。

【问题讨论】:

【参考方案1】:

关键在堆栈跟踪的第一行:

System.ComponentModel.Win32Exception ... Native error= Access denied

运行分析的用户似乎没有应用程序目录所需的权限。具体来说,除了读取所有项目文件之外,它还必须能够创建其数据目录(.sonar)并在该目录中创建和写入文件。

【讨论】:

要添加到文档中的内容? 诚实的问题@JeroenHeier:真的吗?我添加了 this page 关于如何读取堆栈跟踪的内容,但是如果您正在运行 Windows 并且遇到 Windows 错误...或者我在这里没有看到什么? FWIW 我遇到了同样的错误。相同的代码在本地工作,但在我们的 CI 环境 (Jenkins) 中不工作。我可以毫无问题地创建一个 .sonar 目录(和其他目录)。事实上,堆栈跟踪第一行中引用的 .sonar 目录已经存在,并且包含 out/sonar-project.properties。 @NathanialWoolls 你确定该目录上没有前一个进程的挥之不去的锁定吗? @G.Ann-SonarSourceTeam 肯定,我已经单独发布了我的答案。这就是为我解决的问题(chmod)。【参考方案2】:

尝试运行:

chmod +x /Users/magic/Documents/Projects/services/sonar-scanner-msbuild/sonar-scanner-3.0.3.778/bin/sonar-scanner

【讨论】:

感谢@Nathanial Woolls,你拯救了我的一天!

以上是关于Sonarqube C# MsBuild 访问被拒绝的主要内容,如果未能解决你的问题,请参考以下文章

使用 SonarQube Scanner for MSBuild 控制模块名称

如何从解决方案的角度正确配置 SonarQube MSBuild Scanner?

SonarQube 5.6 中的 C# 单元测试结果

构建 C# 应用程序并将结果发送到 SonarQube 仪表板

SonarQube MSBuild 集成失败:

只有 msbuild 14 或 msbuild 15 支持 SonarQube 分析