-
which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
Sonarqube v9.5 build 56709, scanner 4.7.0.2747-linux embedded in sonar-scanner-msbuild-5.7.2.50892-net5 -
what are you trying to achieve
successfully run a scan using cli on linux when using path to SonarScanner.MSBuild.dll -
what have you tried so far to achieve this
Jenkins pipeline stage that follows two paths to achieve the goal. the first path works but requires setup each time. the second path does not work and is the preferred path.
Steps to reproduce (i hope):
- Install contents of sonar-scanner-msbuild-5.7.2.50892-net5.0.zip to a build environment (in my case it’s a container layered off of registry.access.redhat.com/ubi8/dotnet-60:6.0-15.20220727145329)
- set SONAR_HOME to /usr/local/sonar-scanner-4.7.0.2747-linux which contains directories for lib, conf, bin, Targets. dlls, json, xml at /usr/local/sonar-scanner-4.7.0.2747-linux/
- run a pipeline stage that successfully can:
a. dotnet ${SONAR_HOME}/SonarScanner.MSBuild.dll begin
b. dotnet build - run the remaining step that can dotnet ${SONAR_HOME}/SonarScanner.MSBuild.dll end
Expected outcome:
- end completes without issue
Actual outcome:
- end call throws an error
SonarScanner for MSBuild 5.7.2
Using the .NET Core version of the Scanner for MSBuild
Post-processing started.
Calling the SonarScanner CLI...
Execution failed. The specified executable does not exist: /usr/local/sonar-scanner-4.7.0.2747-linux/sonar-scanner-4.7.0.2747/bin/sonar-scanner
The SonarScanner did not complete successfully
00:10:40.336 Post-processing failed. Exit code: 1
Important notes:
end above is looking for sonar-scanner at the wrong path. it seems to be adding the current working directory again to where it’s looking instead of just using $SONAR_HOME. the start stage works as expected.
Full pipeline stage:
stage('Sonarqube') {
container('sonar-scanner-dotnet') {
dir(SRC_LOCATION) { // path to source code location
withSonarQubeEnv('sonarqube') {
sh 'env | grep SONAR_HOME' // debugging for this ticket
# above outputs SONAR_HOME=/usr/local/sonar-scanner-4.7.0.2747-linux
// Initialize sonarqube scan with configuration parameters
sh 'dotnet ${SONAR_HOME}/SonarScanner.MSBuild.dll begin /k:\"' + SONARQUBE_PROJECT_NAME + '\" ' +
'/d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml ' +
'/d:sonar.cs.vstest.reportsPaths=TestResults/*.trx'
// Build the app and generate test coverage and execution data
sh 'dotnet build'
sh 'dotnet ${SONAR_HOME}/SonarScanner.MSBuild.dll end'
}
}
}
}
Output from above with some buildtime stuff removed:
Injecting SonarQube environment variables using the configuration: sonarqube
[Pipeline] {
[Pipeline] sh
+ env
+ grep SONAR_HOME
SONAR_HOME=/usr/local/sonar-scanner-4.7.0.2747-linux
[Pipeline] sh
+ dotnet /usr/local/sonar-scanner-4.7.0.2747-linux/SonarScanner.MSBuild.dll begin /k:enablement:marktest /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml '/d:sonar.cs.vstest.reportsPaths=TestResults/*.trx'
SonarScanner for MSBuild 5.7.2
Using the .NET Core version of the Scanner for MSBuild
Pre-processing started.
Preparing working directories...
00:28:06 Updating build integration targets...
00:28:06.164 Fetching analysis configuration settings...
00:28:06.336 Provisioning analyzer assemblies for cs...
00:28:06.337 Installing required Roslyn analyzers...
00:28:06.547 Provisioning analyzer assemblies for vbnet...
00:28:06.547 Installing required Roslyn analyzers...
00:28:06.574 Pre-processing succeeded.
[Pipeline] sh
+ dotnet build
Microsoft (R) Build Engine version 17.0.0+c9eb9dd64 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.
Determining projects to restore...
<content removed>
Build succeeded.
<content removed>
Time Elapsed 00:00:05.63
[Pipeline] sh
+ dotnet /usr/local/sonar-scanner-4.7.0.2747-linux/SonarScanner.MSBuild.dll end
SonarScanner for MSBuild 5.7.2
Using the .NET Core version of the Scanner for MSBuild
Post-processing started.
Calling the SonarScanner CLI...
Execution failed. The specified executable does not exist: /usr/local/sonar-scanner-4.7.0.2747-linux/sonar-scanner-4.7.0.2747/bin/sonar-scanner
The SonarScanner did not complete successfully
00:28:13.93 Post-processing failed. Exit code: 1
[Pipeline] }
WARN: Unable to locate 'report-task.txt' in the workspace. Did the SonarScanner succeed?