3

Trying to execute a sudo command from my Jenkins executor, I get the title error.

On the host machine(executor) I have configured the sudoers file to contain this line: jenkins ALL=(ALL) NOPASSWD: ALL at the very end.

The command which I am trying to run is sudo service tomcat8 restart.

Checking the available answers I got all I need or am I missing something?

Jacob
  • 3,580
  • 22
  • 82
  • 146

2 Answers2

0

There might be a workaround: As Barmar pointed out in a comment to the post "Use sudo without password INSIDE a script", it is possible to allow a dedicated script be executed by a sudoer. Assume you have a line

 jenkins ALL=(ALL) NOPASSWD:/path/to/restart.sh

this means that Jenkins can do sudo /path/to/restart.sh without a password.

If you now put your command service tomcat8 restart in restart.sh, a sudo /path/to/restart.sh should do the job.

B--rian
  • 5,578
  • 10
  • 38
  • 89
0

Try turning off requiretty for the jenkins user. I would recommend using command aliases in your sudoers file as well.

Cmnd_Alias RESTART_TOMCAT = /sbin/service tomcat8 *, /etc/init.d/tomcat8 *

Defaults:jenkins !requiretty

jenkins  ALL=(root) NOPASSWD: RESTART_TOMCAT
grizzthedj
  • 7,131
  • 16
  • 42
  • 62