-
-
Save imranity/9246dd195f785cf4783d to your computer and use it in GitHub Desktop.
Running shell scripts that have contain sudo commands in them from jenkins might not run as expected. To fix this, follow along | |
Simple steps: | |
1. On ubuntu based systems, run " $ sudo visudo " | |
2. this will open /etc/sudoers file. | |
3. If your jenkins user is already in that file, then modify to look like this: | |
jenkins ALL=(ALL) NOPASSWD: ALL | |
4. save the file by doing Ctrl+O (dont save in tmp file. save in /etc/sudoers, confirm overwrite) | |
5. Exit by doing Ctrl+X | |
6. Relaunch your jenkins job | |
7. you shouldnt see that error message again :) |
It doesn't work in case we SSH connect to server via PHP script. Any ideas?
$ssh->exec("sudo /usr/sbin/nginx -s reload"); // --> sudo: no tty present and no askpass program specified
@nskforward: I'm just guessing here, but try "-S" instead of "-s"
I thinks it's better to grant Jenkins sudo
access only for the script that requires it. Eg.:
jenkins ALL=NOPASSWD:/some-path/some-script
whatever the solution worked superb
Thank god i found this. :)
Thanks! This was very helpful :)
TY! :)
Thanks!
I was trying to run a shell script that executes a command on remote machine from a spark batch and was getting the above error. For now, the above helped by setting this for hdfs user. Thanks!
It worked for me as well
Thanks a lot!
Not working in my case, I am executing shell script from Jenkins server.
- sudo python /home/engineqa/Desktop/LinuxAutomation/execute_test.py
sudo: no tty present and no askpass program specified
Build step 'Execute shell' marked build as failure
Finished: FAILURE
Showing error like that
Thanks!
Not working in my case, I am executing shell script from Jenkins server.
Thanks, it really works!
- sudo python /home/engineqa/Desktop/LinuxAutomation/execute_test.py
sudo: no tty present and no askpass program specified
Build step 'Execute shell' marked build as failure
Finished: FAILUREShowing error like that
Can resolve this error. When you run Jenkins build user will be Jenkins so just run command sudo vim /etc/sudoers and mention %jenkins ALL=(ALL) NOPASSWD:ALL and save.
Hope this will work for you :)
Thanks it's working... 👍
Thanks it's running ... 💯
Hi, i am running a jmeter script from jenkins aws box.I need to write a report file to jmeter folder.It is pulling issue file not found exception.Even though i gave all access .
thanks!
Thanks so much!
In response to the question asked here:
https://stackoverflow.com/questions/25189348/unable-to-provide-password-to-a-process-with-subprocess-python
On linux you can bypass sudo prompt using:
echo <password> | sudo -S whoami
Pass the formatted command to subprocess and you are good to go:
import subprocess as sp
cmd = "whoami"
password= "<password>"
stdout, stderr = sp.Popen("echo {} | sudo -S {}".format(password, cmd), shell=True, stdout=sp.PIPE, stderr=sp.PIPE).communicate()
print(stdout.decode())
if stderr:
print("error occured:")
print(stderr.decode())
It should print root
as command is executed by sudo user.
thanks....
thank u sooo much dude ! u helped me a lot . Thanks again
Thanks!! Worked for me.