Call sudo from Jenkins

Jenkinsnot-root-usersudotty

I have one build machine which has a user abc which is has limited sudo access. When I check out the source code and run my build script, it works fine. The build script contains sudo calls for which it does not say "sudo: no tty present and no askpass program specified". But when I did same thing with Jenkins on a build machine added as slave, it shows "sudo: no tty present and no askpass program specified".

I have found one solution saying to comment out Default requiretty in the file /etc/sudoers. But I don’t have access to this file.

How I can overcome this problem?

Best Answer

There are two options, comment out the Defaults requiretty setting from /etc/sudoers as you mentioned or use the pseudo-tty allocation (-t) argument for ssh.

Try the following in your jenkins script:

ssh -t 127.0.0.1 "sudo command"

Although you will have to have ssh pre-shared keys configured to yourself and run it once manually to add an entry to known hosts, alternatively add the -o StrictHostKeyChecking=no argument to ssh to ignore this.

Related Question