Sudershan Pothina
Sudershan Pothina

Reputation: 11

jenkins pipeline sh not working for few commands

I am trying to run the following command to scan dotnet core project using sonarqube in Jenkins pipeline

    sh "dotnet sonarscanner begin /k:projectkey1"
    sh "dotnet build"
    sh "dotnet sonarscanner end"

Gives me the following error

    + dotnet sonarscanner begin /k:projectkey1
    No executable found matching command "dotnet-sonarscanner"

I can login to the same server as user jenkins and run the same command without any issues. Please help

Upvotes: 1

Views: 2218

Answers (2)

Karthick Prabu
Karthick Prabu

Reputation: 39

You need to set the dotnet tools path in the Jenkins pipeline.

Try:

sh "export PATH=${PATH}:${HOME}/.dotnet/tools"

before your steps in the pipeline:

sh "dotnet sonarscanner begin /k:projectkey1"
sh "dotnet build"
sh "dotnet sonarscanner end"

Upvotes: 1

Jacob Stamm
Jacob Stamm

Reputation: 1873

Be sure that the user account being used for the agent in the pipeline is the same one that you've logged into and installed the sonarscanner global CLI tool on. Because .NET Core Global Tools are user-specific, it won't be available is the users are different.

If you're certain it's the same user, then it's likely caused by cmd.exe needing to be restarted.

If all else fails, you can use SonarScanner.MSBuild.dll for .NET Core instead of the global CLI tool.

Upvotes: 0

Related Questions