Sonarscanner MSBuild tool is not running in pipeline - Jenkins

Viewed 2866

I am running this following pipeline which has stage "Build + Sonarscanner Analysis" for dotnetcore 2.2

The stage is set as follows

  1. I have installed the tool in Global Configuration as suggested by Sonarqube Documentation

enter image description here

  1. Defined the tool in the environment as following
// Tools
        MSBUILD_SQ_SCANNER_HOME = tool name: 'Scanner_for_MSBuild_4.7', type: 'hudson.plugins.sonar.MsBuildSQRunnerInstallation'
  1. Pipeline Stage
stage ('Build + SonarQube analysis') {
            agent {
                docker { 
                    image 'mcr.microsoft.com/dotnet/core/sdk:2.2'
                }
            }
            steps {
                dir ("app") {
                    withSonarQubeEnv('local') {
                        sh "dotnet ${MSBUILD_SQ_SCANNER_HOME}/SonarScanner.MSBuild.dll begin /k:\"Testing-Local\""
                        sh "dotnet build ${env.DotnetProjectName}"
                        sh "dotnet ${MSBUILD_SQ_SCANNER_HOME}/SonarScanner.MSBuild.dll end"
                    }
                }
            }
        }

Result

I am getting the SonarScanner.MSBuild.dll is not executable as seen below

enter image description here

Verfication

  1. The dll exists and the permissions is assigned to Jenkins
  2. The dll is executable
  3. The dll when run manually in that path - it runs

enter image description here

  1. Directly added the path for the dll, It has the same result
stage ('Build + SonarQube analysis') {
            agent {
                docker { 
                    image 'mcr.microsoft.com/dotnet/core/sdk:2.2'
                }
            }
            steps {
                dir ("app") {
                    withSonarQubeEnv('local') {
                        sh "dotnet /var/lib/jenkins/tools/hudson.plugins.sonar.MsBuildSQRunnerInstallation/Scanner_for_MSBuild_4.7/SonarScanner.MSBuild.dll begin /k:\"Testing-Local\""
                        sh "dotnet build ${env.DotnetProjectName}"
                        sh "dotnet var/lib/jenkins/tools/hudson.plugins.sonar.MsBuildSQRunnerInstallation/Scanner_for_MSBuild_4.7/SonarScanner.MSBuild.dll end"
                    }
                }
            }
        }

Thanks for the help in advance.

1 Answers

I was able to solve this,

1. Installed the SonarScanner for dotnetcore in Jenkins Tools

The path for the sonarscanner will be the same as before

Default Path

/var/lib/jenkins/tools/hudson.plugins.sonar.MsBuildSQRunnerInstallation/Scanner_for_MSBuild_4.7/SonarScanner.MSBuild.dll

2. Initialize the tool in Jenkinsfile

// Tools
MSBUILD_SQ_SCANNER_HOME = tool name: 'Scanner_for_MSBuild_4.7', type: 'hudson.plugins.sonar.MsBuildSQRunnerInstallation'
stage ('Build + SonarQube analysis')
      agent {
             docker { 
                  image 'mcr.microsoft.com/dotnet/core/sdk:2.2'
                  args '-v ${MSBUILD_SQ_SCANNER_HOME}:/opt/sonarscanner'
                }
            }
            steps {
                dir ("app") {
                    withSonarQubeEnv('local') {
                        sh "dotnet /opt/sonarscanner/SonarScanner.MSBuild.dll begin /k:\"Testing-Local\""
                        sh "dotnet build ${env.DotnetProjectName}"
                        sh "dotnet /opt/sonarscanner/SonarScanner.MSBuild.dll end"
                    }
                }
            }
        }

How it works?

  1. I am mounting the sonarscanner to the official docker image at the path /opt/sonarscanner/
  2. With the mounted file as an argument for docker container during initialization, now the dll is avaliable for the docker dotnet command
Related