Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a script as root in Jenkins?

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 
like image 595
Mahesh Avatar asked Aug 09 '12 09:08

Mahesh


People also ask

How do I run a script as a root?

To give root privileges to a user while executing a shell script, we can use the sudo bash command with the shebang. This will run the shell script as a root user. Example: #!/usr/bin/sudo bash ....


1 Answers

You must run the script using sudo:

sudo /path/to/script 

But before you must allow jenkins to run the script in /etc/sudoers.

jenkins    ALL = NOPASSWD: /path/to/script 
like image 124
Igor Chubin Avatar answered Sep 22 '22 06:09

Igor Chubin