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
CodePudding user response:
Try changing chmod x 1.sh
into chmod a rx 1.sh
.
Let me know if it worked.
Regards.
CodePudding user response:
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