Best practices to avoid Jenkins error: sudo: no tty present and no askpass program specified

s g picture s g · Jul 2, 2013 · Viewed 37.5k times · Source

When running any sudo command from Jenkins I get the following error: sudo: no tty present and no askpass program specified.

I understand that I can solve this by adding a NOPASSWD entry to my /etc/sudoers file which will allow user jenkins to run commands without needing a password. I can add an entry like this:

%jenkins ALL=(ALL)NOPASSWD:/home/me/dir/script.sh

...but this leads to the following issue: https://stackoverflow.com/questions/17414330/how-to-avoid-specifying-full-path-in-sudoers-file

I can add an entry like this:

%jenkins ALL=NOPASSWD: ALL

...but this allows user jenkins to avoid the password prompt for ALL commands, which seems a bit unsafe. I'm just curious what my options are here, and if there are any best practices I should consider.

Answer

Electrawn picture Electrawn · Sep 27, 2013

The no tty thing (requiretty in sudoers) is the real issue.

Basically, comment out the following lines in your /etc/sudoers file:

#Defaults    requiretty
#Defaults   !visiblepw

Other ways to get it to work:

Defaults    !requiretty

Or per user:

Defaults:jenkins !requiretty

A more detailed answer is this answer to this question on the Unix & Linux Stack Exchange site: