Sonar scanner cli 'end' causing error related to path

  • 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):

  1. 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)
  2. 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/
  3. run a pipeline stage that successfully can:
    a. dotnet ${SONAR_HOME}/SonarScanner.MSBuild.dll begin
    b. dotnet build
  4. run the remaining step that can dotnet ${SONAR_HOME}/SonarScanner.MSBuild.dll end

Expected outcome:

  1. end completes without issue

Actual outcome:

  1. 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?

After writing this, I’m guessing that something in the configuration expects the bin to be in a specific path from where the dlls are in the filesystem?

In my case, my container image has the file structure like:

SONAR_HOME/
SONAR_HOME/SonarScanner.MSBuild.dll
SONAR_HOME/other dlls
SONAR_HOME/lib/*
SONAR_HOME/conf/*
SONAR_HOME/bin/*
SONAR_HOME/Targets/*

instead of the structure from the release zip which, when layered over SONAR_HOME would look like:

SONAR_HOME/
SONAR_HOME/SonarScanner.MSBuild.dll
SONAR_HOME/other dlls
SONAR_HOME/sonar-scanner-4.7.0.2747/lib/*
SONAR_HOME/sonar-scanner-4.7.0.2747/conf/*
SONAR_HOME/sonar-scanner-4.7.0.2747/bin/*
SONAR_HOME/Targets/*

I’ll rebuild and report back. If I missed this part in the documentation about the rigid structure I apologize. This is likely working as expected but I’ve customized it in a way that breaks some internal implementation details about paths.

Hi,

From what I see, this ought to be working. It’s odd that the same path works the first time and fails the second. I’m not aware of any rigid expectations about path structure. I wonder if you’d throw an echo ${SONAR_HOME} in there before the end step just to make sure nothing’s messed with it in the meantime?

 
Thx,
Ann

Thanks for checking it over so quickly, wow. I added an echo and the same value for SONAR_HOME is there so nothing seems to be mucking with it.

I also rebuilt the container image I was using that executes the work to follow the same structure as the .zip file and all is working now. No action seems needed outside of maybe a mention in the documentation at SonarScanner for .NET | SonarQube Docs for troubleshooting and to save anyone else from the same thing. Granted I didn’t dig into it more but from the outside it seems like MSBuild.dll might trigger something downstream about expecting the sonar-scanner to be at a certain path relative to the .dll or maybe a static structure?

Thanks again

1 Like