How to run a script as root in Jenkins?

Viewed 113214

I need to run a shell script in Jenkins as root instead of the default user. What do I need to change?

My sudoers file is like this:

# User privilege specification
root    ALL=(ALL) ALL
igx     ALL=(ALL) ALL
%wheel  ALL=(ALL) ALL

# Allow members of group sudo to execute any command
# (Note that later entries override this, so you might need to move
%sudo   ALL=(ALL) ALL
#
#includedir /etc/sudoers.d

# Members of the admin group may gain root privileges
%admin  ALL=(ALL) NOPASSWD:ALL
root    ALL=(ALL) ALL
jenkins ALL=NOPASSWD: /var/lib/jenkins/workspace/ing00112/trunk/source/
jenkins ALL=(ALL) NOPASSWD:ALL
#Defaults:jenkins !requiretty
5 Answers

Try adding jenkins user to sudo group

sudo su -
usermod -a -G sudo jenkins

Easy way to do it
enter image description here

$ sudo visudo
## Now add the below lines in your sudoers file :
jenkins ALL=(ALL) NOPASSWD: ALL

$service jenkins start
Related