Trying to use SonnarScanner for MSBuild

Hello Jenkins community. I’m new here. I’m using jenkins few weeks ago. I tried everything I could but this error still happening. My Jenkins server is running in a oracle linux 8.2 VM. I set up my project in jenkins as free style project. Configuring my project in Build section I set the step SonarScanner for MSBuild - Begin Analysis, then End Analysis. I configured the SonarScanner for MSBuild in the Global Tool Configuration with SonarScanner for MSBuild 5.0.4.24009 - .NET 5.0. When I click on build now the poject I got the next error:

FATAL: Cannot run program “dotnet” (in directory “/var/jenkins_home/workspace/test_project”): error=2, No such file or directory
java.io.IOException: error=2, No such file or directory
at java.base/java.lang.ProcessImpl.forkAndExec(Native Method)
at java.base/java.lang.ProcessImpl.(ProcessImpl.java:340)
at java.base/java.lang.ProcessImpl.start(ProcessImpl.java:271)
at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1107)
Caused: java.io.IOException: Cannot run program “dotnet” (in directory “/var/jenkins_home/workspace/test_project”): error=2, No such file or directory

I don’t know what to do… Is SonarScanner for MSBuild working wrong in jenkins?

Possibly related TODO comment: sonarqube-plugin/AbstractMsBuildSQRunner.java at a0354923a905e6d3015cd9b58018f55661ed537b · jenkinsci/sonarqube-plugin · GitHub

According to that code, the plugin tries to run “dotnet” without specifying a path, and assumes that Launcher finds the executable by searching the directories listed in the PATH environment variable.

Did you install the .NET 5 SDK in such a way that the “dotnet” executable is somewhere on the PATH? Perhaps you should add its installation directory to the PATH environment variable.

Does your freestyle project use “dotnet” for the build itself, and would that part work OK if you removed the sonarqube steps?

I didn’t find a Jira issue corresponding to the TODO comment but [JENKINS-65531] sonar scanner for msbuild with dotnet core 5 - Jenkins Jira at least mentions using sonarqube with msbuild.

1 Like

Hi @kon
I’m facing this issue.
To debug, I added a Execute shell step before the sonar scanner step to check dotnet version and it showed the version.

echo "$PATH"
export DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1
dotnet --version

But then in the sonar scanner step, dotnet not found as if it was not in the PATH

[WebAPI] $ /bin/sh -xe /tmp/jenkins3636744107552792716.sh
+ echo /var/jenkins_home/tools/io.jenkins.plugins.dotnet.DotNetSDK/.NET-Core-3.1:/opt/java/openjdk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
/var/jenkins_home/tools/io.jenkins.plugins.dotnet.DotNetSDK/.NET-Core-3.1:/opt/java/openjdk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
+ export DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1
+ dotnet --version
3.1.426
[WebAPI] $ dotnet /var/jenkins_home/tools/hudson.plugins.sonar.MsBuildSQRunnerInstallation/SonarScanner_for_MSBuild_5.13/SonarScanner.MSBuild.dll begin /k:d5_d5-training_learningproject_for-jenkins-prj_AYqsgSb58pmjtyrbg2Z2 /n:WebAPI /v:1.0 /d:sonar.host.url=https://sonar.mydomain.com ********
FATAL: Cannot run program "dotnet" (in directory "/var/jenkins_home/workspace/cicd-test/D5/C_Sharp/WebAPI"): error=2, No such file or directory
java.io.IOException: error=2, No such file or directory
	at java.base/java.lang.ProcessImpl.forkAndExec(Native Method)

Please give me some suggestions. Thank you in advance.