Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

permission denied when executing the jenkins sh pipeline step

I have some trouble with this situation: everytime I create a new pipeline job ( entitled "pipeline"), the sh step won't work even with simple command like ls or pwd and it returns this log:

sh: 1: /var/jenkins_home/workspace/pipeline@tmp/durable-34c21b81/script.sh: Permission denied

Any suggestions?

like image 329
Tayeb Ben Achour Avatar asked Apr 12 '17 14:04

Tayeb Ben Achour


People also ask

How do I fix Permission denied in Jenkins?

To fix the Jenkins Docker permission denied error, just run a usermod command in the terminal and reboot.

How do I fix Permission denied in shell?

For solving this error, you need to add the correct permissions to the file to execute. However, you need to be a “root” user or have sudo access for changing the permission. For changing the permission, Linux offers a chmod command. The chmod stands for change mod.

How do I fix bash permission denied?

Usually, you get the error bash permission denied when running some script/file that does not have execute permissions. It is one of the most common Magento errors. All you need to do to fix it is to change file permissions and add executive one.


2 Answers

I guess you use

stage(name){
   sh ./runSomething
}

Jenkins always uses to user jenkins for running scripts. There are some possibilities:

  1. Jenkins is running with a different user, maybe you start it with some other user.
  2. Something went running when installing jenkins, check that you have a jenkins user
like image 110
Torsten Avatar answered Sep 22 '22 10:09

Torsten


I was getting a similar permissions denied error after following the Jenkins pipeline tutorial for a node project.

./jenkins/test.sh: Permission denied

The original pipeline Test stage looked like the following and returned that error.

stage('Test') {
    steps {
        sh './jenkins/test.sh'
    }
}

I found the following post: https://stackoverflow.com/a/61956744/9109504 and modified the Test stage to the following

stage('Test') {
    steps {
        sh "chmod +x -R ${env.WORKSPACE}"
        sh './jenkins/test.sh'
    }
}

That change fixed the permissions denied error.

like image 39
onewithpaddle Avatar answered Sep 23 '22 10:09

onewithpaddle