How to run a script as root in Jenkins?
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
@Igor Chubin's answer is 100% correct, but never open sudoer file with a normal editor. always use visudo
just type
sudo visudo
this will take you to /etc/sudoers
and upon saving it will make sure that there is no error in formatting.
if you make an error in sudoer file, you will lose sudo access, so always use visudo