'Getting permission denied while executing shell script in jenkins pipeline
I have created new user as admin in linux and given required permissions ( Added in visudo ).
I have just created new folder and added script to it as below.
/home/admin/test/1.sh
- sh contains below
#!/bin/bash
echo hello
then given executable permission to the 1.sh.
chmod +x 1.sh and also given full permissions to the folders as well.
chmod 777 test and it is working fine when i executed directly in linux server.
Created jenkins pipeline job as below.
pipeline {
agent any
stages {
stage ('Testing bash script') {
steps {
sh '/home/admin/test/1.sh'
}
}
}
}
When i have executed it in jenkins then got below error. Not sure why it is getting failed.
Please help here.
/var/lib/jenkins/workspace/TestScript@tmp/durable-c6024b58/script.sh: line 1: /home/admin/test/1.sh: Permission denied
Solution 1:[1]
I've had the same issue and to solve I simply created a new script, added execution permissions from the start, and changed the references in my Jenkinsfile (ofc).
After doing this somehow I could overcome the error.
Solution 2:[2]
Try changing chmod +x 1.sh into chmod a+rx 1.sh.
Let me know if it worked.
Regards.
Solution 3:[3]
You didn't say what exactly system you are using but eg if it's Centos it can be related to SELinux so you can switch it into permissive mode and try again. Anyway good thing to do is to switch to user jenkins (or any other that is used to run Jenkins) using sudo / su and then try to execute this script from shell. To list privileges on whole path where script is located is convenient to use namei -l /home/admin/test/1.sh
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | ReAlm |
| Solution 2 | Antonio Petricca |
| Solution 3 | Krzysztof Ksi??yk |
