29

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.

Community
  • 1
  • 1
s g
  • 5,289
  • 10
  • 49
  • 82
  • I could not get which file you are changing with this command? %jenkins ALL=(ALL)NOPASSWD:/home/vts_share/test/sudotest.sh I am trying to use sudo command also in jenkins, so I need to know which file I should run this command? – meakgoz Feb 26 '14 at 12:29
  • It was a specific file on my machine, I've edited the post to show a generic file – s g Feb 28 '14 at 17:18

2 Answers2

14

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:

Electrawn
  • 2,254
  • 18
  • 24
  • My /etc/sudoers file does not contain either of those lines, but even after adding lines to sudoers to allow my user to use a command, I still get the "sudo: no tty present and no askpass program specified" error. – Eliezer Miron Feb 20 '20 at 18:08
4

One thing you can do is to get Jenkins to run a script, for example 'run.sh', then from inside this script you can start makefiles, and make sure that there are no sudo commands inside the makefiles.

It is a bit of a hassle, but at least you are not risking changing security settings

serup
  • 3,676
  • 2
  • 30
  • 34