sonar-scanner-msbuild
sonar-scanner-msbuild copied to clipboard
[UNIX] `Begin` step should fail early if `sonar-scanner` is not executable
This is related to #493.
The problem
Currently, at the END
step the scanner is failing on Unix systems because the executable bit is not set on the scanner-cli. The error looks like below.
andrei@S4NET:$ dotnet ~/2022-08-04-autoscan/s560/SonarScanner.MSBuild.dll end /d:sonar.login="<TOKEN>"
SonarScanner for MSBuild 5.6
Using the .NET Core version of the Scanner for MSBuild
Post-processing started.
Calling the SonarScanner CLI...
Unhandled exception. System.ComponentModel.Win32Exception (13): An error occurred trying to start process '/home/andrei/2022-08-04-autoscan/s560/sonar-scanner-4.6.2.2472/bin/sonar-scanner' with working directory '/home/andrei/2022-08-04-autoscan/projects_560/WebConfig.CS'. Permission denied
//...
// big ugly stacktrace
//...
This is bad user experience because:
- there is a hard failure after the BEGIN step and the build analysis executed successfully
- the user will be confused by the stack trace
- instead of a nice error message for this well-known scenario, we fail clumsily with a huge stack trace
My proposal
Fail at the BEGIN
step if the sonar-scanner
does not have the executable bit set. This check can easily be done during the begin step.
Furthermore, the scanner should first attempt to set the executable bit, catch the exception if not allowed and fail with a nice error message like:
Error: could not run
chmod +x
onsonar-scanner
. In order to run, the Scanner for .NET needs to executesonar-scanner
during the END step. Please runchmod +x
on thesonar-scanner
to allow its execution.
If I have the following step in a dockerfile:
RUN sudo dotnet tool install dotnet-sonarscanner --tool-path /usr/local/bin
With the container running, it results in the following on dotnet sonarscanner end
:
An error occurred trying to start process '/usr/local/bin/.store/dotnet-sonarscanner/5.13.0/dotnet-sonarscanner/5.13.0/tools/net5.0/any/sonar-scanner-4.8.0.2856/bin/sonar-scanner' with working directory ...
Is there a recommended approach to determining that path, or should +x
be set at a higher level?
Hi @JohnYoungers - could you please ask the question on https://community.sonarsource.com/ ? We monitor that for such questions, and it's better suited for discussions and clarifications. Thanks.