Fixed 'sudo: no tty present and no askpass program specified'?

I was trying to run some commands on agent machines using Jenkins  and those commands needed   “sudo” access as Jenkins was not running under root user. Those commands resulted in following error

1 2 3   sudo: no tty present and no askpass program specified  

After googling i found that its related to sudo previleges.

How i Fixed “no tty present and no askpass program specified’ error ?

Granting the user to run the commands without prompting for password resolved the problem.

Login to machine and edit the /etc/sudoers file using any of the following

1 2 3   sudo visudo  

Or

1 2 3   sudo vi /etc/sudoers  

Add the following line at the END OF THE FILE

1 2 3   jenkins ALL=(ALL) NOPASSWD: ALL  

You can replace the user “jenkins” with the username which give this error

Please make sure you are adding these lines at the end of the file. Else it might not work, as there can be other configuration entries conflicting with the above entry. Placing this line at the end of the file will make sure the new line will get the priority.

After adding this line i was able to run sudo command successfully.

Author: , 0000-00-00