Run a shell from Jenkins using sudo (Ubuntu)


Running shell commands which have sudo might not worked as expected as jenkins doesn’t have access to read passwords from your linux box.

Are you familiar with below error?

sudo: no tty present and no askpass program specified

Jenkins use your linux box with user called “jenkins”. We might want to tell the OS not to ask password while executing commands.

Below are the steps to achieve this.

#1 open /etc/sudoers

type sudo vi  /etc/sudoers. This will open your file in edit mode.

#2 Add/Modify jenkins user

Look for the entry for jenkins user. Modify as below if found or add a new line.


#3 Save and Exit from edit mode

Press ESC and type :wq and hit Enter. You should be out of the edit mode.

Please try to re-run you Jenkins job. You should not see the above mentioned error and sudo commands will run without any problem.


S with ♥

3 thoughts on “Run a shell from Jenkins using sudo (Ubuntu)

  1. It is bad to edit directly the sudoers file with vi, because, if you do an error, you lost all super permission. The better way is to use visudo which generate a tmp file and validate the sudoerfile before saving

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s