'permission denied while building project in jenkins . /tmp/jenkins7547483698503669612.sh: line 2: /root/hello.sh: Permission denied

I am facing an issue when I am trying to run the Jenkins job. I have tried to change the permission of the script, but it seems the error persisted.

chmod -R 777 file_name.sh


Solution 1:[1]

@Vivek Joshi I guess the problem is ownership of hello.sh is 'root' user and your jenkins job runs with 'jenkins' user. (Installing and running jenkins with root user is not recommended)

You can try something below

  1. Change ownership of hello.sh file to jenkins user
chown jenkins:jenkins hello.sh
  1. Move hello.sh file to jenkins workspace directory and try to run job again
mv <path to directory where hello.sh is present> <jenkins workspace directory>

Eg : mv /home/user/hello.sh /jenkins/workspace/

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 Tapan Hegde