SonarCloudAnalayze and SonarCloudPrepare can't find SonarScanner.MSBuild.exe

Hello,

I’m trying to run SonarCloud tasks on self-hosted agent (Windows Server 2019) and it just does not work.
The SonarCloudPrepare task is failing with below error:

##[error]There was an error when attempting to execute the process 'C:\Agent2\_work\_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\1.40.2\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe'. This may indicate the process failed to start. Error: spawn C:\Agent2\_work\_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\1.40.2\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe ENOENT

The full log:

##[debug]SonarCloud or SonarQube version >= 7.2.0 detected, setting report-task.txt file to its newest location.
##[debug]Agent.TempDirectory=C:\Agent2\_work\_temp
##[debug]Build.BuildId=5672
##[debug][SQ] Branch and PR parameters: {"sonar.branch.name":"feature/sonarcloud-integration","sonar.scanner.metadataFilePath":"C:\\Agent2\\_work\\_temp\\sonar\\5672\\5b9fc323-5237-6d18-7640-d1baad6390d9\\report-task.txt"}
##[debug]extraProperties=# Additional properties that will be passed to the scanner, 
# Put one key=value per line, example:
# sonar.exclusions=**/*.bin
##[debug]set SONARQUBE_SERVER_VERSION=8.0.0
##[debug]Processed: ##vso[task.setvariable variable=SONARQUBE_SERVER_VERSION;isOutput=false;issecret=false;]8.0.0
##[debug]set SONARQUBE_SCANNER_MODE=MSBuild
##[debug]Processed: ##vso[task.setvariable variable=SONARQUBE_SCANNER_MODE;isOutput=false;issecret=false;]MSBuild
##[debug]set SONARQUBE_SCANNER_REPORTTASKFILE=C:\Agent2\_work\_temp\sonar\5672\5b9fc323-5237-6d18-7640-d1baad6390d9\report-task.txt
##[debug]Processed: ##vso[task.setvariable variable=SONARQUBE_SCANNER_REPORTTASKFILE;isOutput=false;issecret=false;]C:\Agent2\_work\_temp\sonar\5672\5b9fc323-5237-6d18-7640-d1baad6390d9\report-task.txt
##[debug]set SONARQUBE_ENDPOINT=********
##[debug]Processed: ##vso[task.setvariable variable=SONARQUBE_ENDPOINT;isOutput=false;issecret=true;]***
##[debug]extraProperties=# Additional properties that will be passed to the scanner, 
# Put one key=value per line, example:
# sonar.exclusions=**/*.bin
##[debug]set SONARQUBE_SCANNER_MODE=MSBuild
##[debug]Processed: ##vso[task.setvariable variable=SONARQUBE_SCANNER_MODE;isOutput=false;issecret=false;]MSBuild
##[debug]set SONARQUBE_ENDPOINT=********
##[debug]Processed: ##vso[task.setvariable variable=SONARQUBE_ENDPOINT;isOutput=false;issecret=true;]***
##[debug]set SONARQUBE_SCANNER_PARAMS={"sonar.host.url":"https://sonarcloud.io/","sonar.token":***,"sonar.organization":"test","sonar.projectKey":"testproject","sonar.projectName":"testproject","sonar.projectVersion":"1.0","sonar.branch.name":"feature/sonarcloud-integration","sonar.scanner.metadataFilePath":"C:\\Agent2\\_work\\_temp\\sonar\\5672\\5b9fc323-5237-6d18-7640-d1baad6390d9\\report-task.txt"}
##[debug]Processed: ##vso[task.setvariable variable=SONARQUBE_SCANNER_PARAMS;isOutput=false;issecret=false;]{"sonar.host.url":"https://sonarcloud.io/","sonar.token":***,"sonar.organization":"test","sonar.projectKey":"testproject","sonar.projectName":"testproject","sonar.projectVersion":"1.0","sonar.branch.name":"feature/sonarcloud-integration","sonar.scanner.metadataFilePath":"C:\\Agent2\\_work\\_temp\\sonar\\5672\\5b9fc323-5237-6d18-7640-d1baad6390d9\\report-task.txt"}
##[debug]Absolute path for pathSegments: C:\Agent2\_work\_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\1.40.2,classic-sonar-scanner-msbuild,SonarScanner.MSBuild.exe = C:\Agent2\_work\_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\1.40.2\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe
##[debug]Using classic scanner at C:\Agent2\_work\_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\1.40.2\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe
##[debug]set SONARQUBE_SCANNER_MSBUILD_EXE=C:\Agent2\_work\_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\1.40.2\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe
##[debug]Processed: ##vso[task.setvariable variable=SONARQUBE_SCANNER_MSBUILD_EXE;isOutput=false;issecret=false;]C:\Agent2\_work\_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\1.40.2\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe
##[debug]which 'C:\Agent2\_work\_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\1.40.2\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe'
##[debug]found: 'C:\Agent2\_work\_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\1.40.2\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe'
##[debug]C:\Agent2\_work\_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\1.40.2\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe arg: begin
##[debug]C:\Agent2\_work\_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\1.40.2\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe arg: /k:testproject
##[debug]C:\Agent2\_work\_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\1.40.2\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe arg: /o:test
##[debug]system.debug=True
##[debug]exec tool: C:\Agent2\_work\_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\1.40.2\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe
##[debug]arguments:
##[debug]   begin
##[debug]   /k:testproject
##[debug]   /o:test
C:\Agent2\_work\_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\1.40.2\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe begin /k:testproject /o:test
##[debug]task result: Failed
##[error]There was an error when attempting to execute the process 'C:\Agent2\_work\_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\1.40.2\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe'. This may indicate the process failed to start. Error: spawn C:\Agent2\_work\_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\1.40.2\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe ENOENT
##[debug]Processed: ##vso[task.issue type=error;]There was an error when attempting to execute the process 'C:\Agent2\_work\_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\1.40.2\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe'. This may indicate the process failed to start. Error: spawn C:\Agent2\_work\_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\1.40.2\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe ENOENT
##[debug]Processed: ##vso[task.complete result=Failed;]There was an error when attempting to execute the process 'C:\Agent2\_work\_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\1.40.2\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe'. This may indicate the process failed to start. Error: spawn C:\Agent2\_work\_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\1.40.2\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe ENOENT
Finishing: SonarCloudPrepare

When I enter SonarScanner.MSBuild.exe directory and try to run the file manually or from the powershell/cmd, it fails with error that exe file cannot be found.

C:\Agent2\_work\_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\1.40.2\classic-sonar-scanner-msbuild>SonarScanner.MSBuild.exe
The system cannot find the file C:\Agent2\_work\_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\1.40.2\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe.

If I just change the folder name, for example from 1.40.2 to 1.40.21, I can run the SonarScanner.MSBuild.exe without problem but of course Pipeline fails because it expect to find the SonarScanner.MSBuild.exe inside the folder to which task has been downloaded.

C:\Agent2\_work\_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\1.40.21\classic-sonar-scanner-msbuild>SonarScanner.MSBuild.exe
SonarScanner for MSBuild 5.14
Using the .NET Framework version of the Scanner for MSBuild

Usage on SonarQube:

  SonarScanner.MSBuild.exe [begin|end] /key:project_key [/name:project_name] [/version:project_version] [/s:settings_file] [/d:sonar.token=token] [/d:sonar.{property_name}=value]

Usage on SonarCloud:

  SonarScanner.MSBuild.exe [begin|end] /key:project_key [/name:project_name] [/version:project_version] [/s:settings_file] [/d:sonar.login=token] [/d:sonar.{property_name}=value]

The agent run on my localadmin profile and it has all the access rights. I don’t understand why I can get it working by changing just the folder name. It does not make any sense.

Hi,

What I’m actually seeing is this:

Is the scanner executable (permission-wise)?

 
Ann