6

I have a Sonarqube (6.7.1) server with SonarC# (6.7.1) which is build by Bitnami Google Cloud Platform.

and I followed the tutorial: https://docs.sonarqube.org/display/SCAN/Scanning+on+Linux+or+macOS

created a new and empty project 'ConsoleApp1'

However in the last step: mono ~/Tools/ScannerMSBuild/SonarQube.Scanner.MSBuild.exe end /d:sonar.login=XYZ

It will popup an exception:

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

Does anyone know how to fix the issue? Thank you very much.

WeiHan Hung
  • 155
  • 1
  • 7

2 Answers2

11

Try running:

chmod +x /Users/magic/Documents/Projects/services/sonar-scanner-msbuild/sonar-scanner-3.0.3.778/bin/sonar-scanner
Nathanial Woolls
  • 5,231
  • 24
  • 32
0

The crux is found in the first line of the stacktrace:

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

It appears that the user running the analysis doesn't have the permissions it needs to the application directory. Specifically, in addition to reading all the project files, it must be able to create its data directory (.sonar) and create and write to files in that dir.

G. Ann - SonarSource Team
  • 22,346
  • 4
  • 40
  • 76
  • Something to add to the documentation? – Jeroen Heier Feb 05 '18 at 20:24
  • Honest question @JeroenHeier: really? I added [this page](https://docs.sonarqube.org/display/SONAR/Troubleshooting) on how to read a stacktrace, but if you're running Windows and you get a Windows error... Or am I not seeing something here? – G. Ann - SonarSource Team Feb 05 '18 at 20:50
  • FWIW I'm getting the same error. The same code works locally but not in our CI environment (Jenkins). I can create a .sonar directory (and other directories) without a problem. In fact the .sonar directory referenced in the first line of the stack trace already exists, and contains out/sonar-project.properties. – Nathanial Woolls Feb 07 '18 at 06:00
  • @NathanialWoolls are you sure there isn't a lingering lock on that directory from a previous process? – G. Ann - SonarSource Team Feb 07 '18 at 12:12
  • 1
    @G.Ann-SonarSourceTeam positive, I've posted my answer separately. That is what solved it for me (chmod). – Nathanial Woolls Feb 07 '18 at 13:10