Durable-c22d6eb4/script.sh: 1: dotnet: Permission denied

Hello I am using sonarscanner in jenkins and the following code

stage("SonarQube scan") {
steps {
script {
def scannerHome = tool 'SonarQube-1'
println "${scannerHome}"
withSonarQubeEnv(installationName: 'sonarqubeElets') {
sh "dotnet ${scannerHome}/SonarScanner.MSBuild.dll begin /k:\"vladimir\""
sh "dotnet build"
sh "dotnet ${scannerHome}/SonarScanner.MSBuild.dll end"
}

And I get the following error
durable-c22d6eb4/script.sh: 1: dotnet: Permission denied
Please tell me what it can be connected with

Hi,

Welcome to the community!

This is an unfortunately vague error. You should make sure that the user account running the pipeline has permissions to read/execute the scanner, and full (rwx) permissions to the project directory.

 
HTH,
Ann

Hello, can you please tell me how can I check this? I just run everything in jenkins. Can you please advise how I can set this up?

Hi,

This is on the OS / Jenkins side. What user is Jenkins running as on that build agent? And does that user account have full permissions to the Jenkins work directory?

 
Ann


I think that under the user jenkins. The rights to the directory are standard. Jenkins owner: jenkins 755

Did I write something wrong?

Hi @VladimirKazantsev ,

can you maybe output some debug statements? like

sh "which dotnet"
sh "ls -alh $(which dotnet)"

and maybe you can just try to set the executable bit to the dotnet tool to see if this is already sufficient (sh "chmod +x $(which dotnet)") ?

Here is my step, please tell me where I should insert it ?

stage("SonarQube scan") {
				
				steps {
					echo "===============Scan Sonar======================="
					
					script {
						git branch: "main",
								url: "git@github.com:VladimirKazantsev/c-app.git"
						def scannerHome = tool 'SonarQube-1'
						withSonarQubeEnv(installationName: 'sonarqubeElets') {
						sh "dotnet ${scannerHome}/SonarScanner.MSBuild.dll begin /k:\"testVladimir\" /d:sonar.verbose=true /d:sonar.login="sqp_5111c5b096cf74f8f17cccb9c0bd3d8de1ebf943""
						sh "dotnet build Helloworld.csproj"
						sh "dotnet ${scannerHome}/SonarScanner.MSBuild.dll end /d:sonar.login="sqp_5111c5b096cf74f8f17cccb9c0bd3d8de1ebf943""
						}
					}
				} 
			}

Before the first call to dotnet

Did so

stage("SonarQube scan") {
				
				steps {
					echo "===============Scan Sonar======================="
					
					script {
						git branch: "main",
								url: "git@github.com:VladimirKazantsev/c-app.git"
						def scannerHome = tool 'SonarQube-1'
						withSonarQubeEnv(installationName: 'sonarqubeElets') {
						sh "which dotnet"
						sh "dotnet ${scannerHome}/SonarScanner.MSBuild.dll begin /k:\"testVladimir\" /d:sonar.verbose=true /d:sonar.login="sqp_5111c5b096cf74f8f17cccb9c0bd3d8de1ebf943""
						sh "dotnet build Helloworld.csproj"
						sh "dotnet ${scannerHome}/SonarScanner.MSBuild.dll end /d:sonar.login="sqp_5111c5b096cf74f8f17cccb9c0bd3d8de1ebf943""
						}
					}
				} 
			}

Here is my output

Okay so there is no dotnet installed in the path env of the Jenkins node?

What should I check now? Or what settings to show?

install dotnet code on the jenkins node that you want to run the analysis on i would assume. If i recall correctly the jenkins plugin for sonarqube will only inject some configuration and not take care of the provisioning of your build nodes.
You can find more information about the requirements of the dotnet scanner here: SonarScanner for .NET | SonarQube Docs
Additionally here is a tutorial how to manually install dotnet core on ubuntu 20.04: How to Install Dotnet Core on Ubuntu 20.04 – TecAdmin

hope that helps you sort this out

1 Like

Thank you so much! Tomorrow I will try. And I will definitely give you feedback.

Here are the packages I installed, but the dotnet --version command doesn’t work. Is that how it should be?

Sorry, I made a mistake, I created the directory /usr/bin/dotnet/ before installing dotnet. Because of this, the dotnet installation did not work correctly. I fixed it and everything worked. Thank you! But there is one more question, a little later I will write it.

If I execute code like this

stage("SonarQube scan") {
				
				steps {
					echo "===============Scan Sonar======================="
					
					script {
						git branch: "main",
								url: "git@github.com:VladimirKazantsev/c-app.git"
						def scannerHome = tool 'SonarQube-1'
						sh "ls"
						sh "pwd"
						println "${scannerHome}"
						withSonarQubeEnv(installationName: 'sonarqubeElets') {
						sh "which dotnet"
						sh "dotnet ${scannerHome}/SonarScanner.MSBuild.dll begin /k:\"testVladimir\" /d:sonar.verbose=true /d:sonar.login=\"sqp_5111c5b096cf74f8f17cccb9c0bd3d8de1ebf943\""
						sh "dotnet build Helloworld.csproj"
						sh "dotnet ${scannerHome}/SonarScanner.MSBuild.dll end /d:sonar.login=\"sqp_5111c5b096cf74f8f17cccb9c0bd3d8de1ebf943\""
						}
					}
				} 
			}

Then I get the following error

+ dotnet /var/lib/jenkins/tools/hudson.plugins.sonar.SonarRunnerInstallation/SonarQube-1/SonarScanner.MSBuild.dll begin /k:testVladimir /d:sonar.verbose=true /d:sonar.login=sqp_5111c5b096cf74f8f17cccb9c0bd3d8de1ebf943
17:40:46  Failed to execute because the specified command or the specified file could not be found.
17:40:46  Possible reasons:
17:40:46    * you mistyped the built-in dotnet command;
17:40:46    * you were planning to run a .NET program, but it dotnet-/var/lib/jenkins/tools/hudson.plugins.sonar.SonarRunnerInstallation/SonarQube-1/SonarScanner.MSBuild.dll doesn't exist;
17:40:46    * you wanted to run a global tool, but the path specified in PATH could not find an executable file with the dotnet prefix that has this name.

image

Thank you very much! Understood! You are best! Thanks for the help! Here is the solution:
changed the variable


1 Like

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