Jenkins working with sonaranalysis for mvn but not for dotnet

Hello all. Quite new with sonnar. So far I was able to configure in jenkins my sonarqube server and run maven apps with following code.

    withSonarQubeEnv('sonarserver') {

     sh 'mvn clean package sonar:sonar'
     s
        
    }       

This runs successfully and do the analysis plus the maven build and generates a war file.

Now I´m trying to do the same for .net core app. I installed sonarscanner following this link

First step was successfully run

dotnet tool install --global dotnet-sonarscanner

I got:

dotnet tool install --global dotnet-sonarscanner
Since you just installed the .NET Core SDK, you will need to logout or restart your session before running the tool you installed.
You can invoke the tool using the following command: dotnet-sonarscanner

So I created following code next:

 withSonarQubeEnv('sonarserver') {
       sh '''
          
          dotnet-sonarscanner begin /k:"proyject-key"
          dotnet build solution.sln
          dotnet-sonarscanner end
        
        '''

But now I´m getting:

+ dotnet-sonarscanner begin /k:project-key
/var/lib/jenkins/workspace/sonar-test-dotnet@tmp/durable-00ff368b/script.sh: 3: /var/lib/jenkins/workspace/sonar-test-dotnet@tmp/durable-00ff368b/script.sh: dotnet-sonarscanner: not found
[Pipeline] }
WARN: Unable to locate 'report-task.txt' in the workspace. Did the SonarScanner succeed?

What Am I missing and how can I configure it? Didn´t the sonnar scanner already installed in first step?

Thank you!

Hi @yiyito

I’m no .net developer so i’m also looping in @mickaelcaro for the .net perspective.

I did notice that the documentation you linked refers to dotnet sonarscanner begin .... and dotnet sonarscanner end and in your code snippet I see a - between dotnet and sonarscanner. Could this be the issue?
This is also something I see in the log output dotnet-sonarscanner: not found.

I think your snippet should look like this:

withSonarQubeEnv('sonarserver') {
       sh '''
          
          dotnet sonarscanner begin /k:"project-key"
          dotnet build solution.sln
          dotnet sonarscanner end
        
        '''

Hi @yiyito

Can you check that the .dotnet folder (usually $HOME/.dotnet/tools) where your tool and SDKs might be installed is registered on your $PATH env variable ?

Hey guys sorry for the delay on the reply.

I solved it with following:

stage('Sonarqube analysis ') {

        environment { 

            //def scannerHome = tool 'SonarScanner 4.10.0'

            MSBUILD_SQ_SCANNER_HOME = tool name: 'sonarscanner', type: 'hudson.plugins.sonar.MsBuildSQRunnerInstallation'

                }

        steps {

        withSonarQubeEnv('sonarserver') {

            sh 'dotnet restore'

            sh ("""dotnet ${MSBUILD_SQ_SCANNER_HOME}/SonarScanner.MSBuild.dll begin /k:'app_key'""")

            sh "dotnet build app.sln"

            sh "dotnet ${MSBUILD_SQ_SCANNER_HOME}/SonarScanner.MSBuild.dll end"

        }

the tool name: 'sonarscanner' was configured in Jenkins in global Tools configuration with that name

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.