I have recently started using Jenkins for integration. All was well until I was running jobs on master node without shell command but I have to run jobs on master as well as slave node which contains shell commands to. I am not able to run those shell commands as root user. I have tried
SSH Keys
. sudo
.I am getting permission denied
error every time I use any of the above methods.
I would suggest against running the jenkins user as root. This could expose the operating system and all of the repo's which jenkins can build.
Running any script as root is a security risk, but a slightly safer method would be to grant the jenkins user sudo access to only run the one script, without needing a password.
sudo visudo
and add the following:
jenkins ALL = NOPASSWD: /var/lib/jenkins/jobs/[job name]/workspace/script
Double check your path via the console log of a failed build script. The one shown here is the default.
Now within the jenkins task you can call sudo $WORKSPACE/your script