Madura Dissanayake
Madura Dissanayake

Reputation: 8729

Run commands via Jenkins?

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.

Upvotes: 2

Views: 1434

Answers (2)

Tiago Lopo
Tiago Lopo

Reputation: 7959

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.

Upvotes: 2

uncletall
uncletall

Reputation: 6842

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.

Upvotes: 2

Related Questions