Sonarqube C# MsBuild访问被拒绝

7
我有一个Sonarqube服务器(6.7.1版本),安装了SonarC#(6.7.1版本),使用的是Bitnami Google Cloud平台。
我按照教程进行操作:https://docs.sonarqube.org/display/SCAN/Scanning+on+Linux+or+macOS,创建了一个新的空项目“ConsoleApp1”。
然而,在最后一步中: mono ~/Tools/ScannerMSBuild/SonarQube.Scanner.MSBuild.exe end /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

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

2个回答

14

尝试运行:

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

谢谢@Nathanial Woolls,你救了我的一天! - WeiHan Hung

0
核心问题可以在堆栈跟踪的第一行中找到:
System.ComponentModel.Win32Exception ... Native error= Access denied

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


有什么需要添加到文档中的吗? - Jeroen Heier
诚实的问题@JeroenHeier:真的吗?我添加了此页面,以说明如何读取堆栈跟踪,但如果您正在运行Windows并且遇到Windows错误...或者我没有看到什么? - G. Ann - SonarSource Team
就我所知,我也遇到了同样的错误。相同的代码在本地可以运行,但在我们的CI环境(Jenkins)中却无法运行。我可以轻松创建一个.sonar目录(以及其他目录)。事实上,在堆栈跟踪的第一行引用的.sonar目录已经存在,并包含out/sonar-project.properties文件。 - Nathanial Woolls
@NathanialWoolls 你确定之前的进程中没有对该目录存在着悬挂的锁定吗? - G. Ann - SonarSource Team
1
@G.Ann-SonarSourceTeam 没问题,我已经单独发布了我的答案。这就是解决问题的方法(chmod)。 - Nathanial Woolls

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接