2

I have a script on remote Ubuntu server. I trying to execute the script after the jenkins build is succeeded, But the error says like this:

sudo: no tty present and no askpass program specified

The configuration is given below, enter image description here

Can anyone help me? Thank You.

Madura Dissanayake
  • 8,309
  • 5
  • 25
  • 34
  • See http://stackoverflow.com/questions/21659637/sudo-no-tty-present-and-no-askpass-program-specified-netbeans – uncletall Jun 30 '14 at 08:06

2 Answers2

2

The problem is that your script uses sudo at some point. The usual way around is to add the script that requires you to use sudo to the sudoers.

Example: in your script you use sudo service apache2 reload, now create a bash script containing that line and add that script to the sudoers file.

New script name: /home/quaser/restart-apache.sh

Use: visudo

Add at bottom of the file:

jenkins ALL=(ALL) NOPASSWD: /home/quaser/restart-apache.sh

Now, in your script change: sudo service apache restart to sudo /home/quaser/restart-apache.sh and you should not be asked for a password.

uncletall
  • 6,609
  • 1
  • 27
  • 52
2

I had the same problem, I solved that by commenting Defaults requiretty on /etc/sudoers

cat /etc/sudoers| grep tty
#Defaults    requiretty

From the man page:

 man sudoers | grep requiretty  -A 5
       requiretty      If set, sudo will only run when the user is logged in
                       to a real tty.  When this flag is set, sudo can only be
                       run from a login session and not via other means such
                       as cron(8) or cgi-bin scripts.  This flag is off by
                       default.
Tiago Lopo
  • 7,619
  • 1
  • 30
  • 51