2014-06-30 288 views
2

我在远程Ubuntu服务器上有一个脚本。我想詹金斯打造的是成功后执行脚本,但错误说是这样的:通过Jenkins运行命令?

sudo: no tty present and no askpass program specified 

的配置如下, enter image description here

谁能帮助我? 谢谢。

+0

见http://stackoverflow.com/questions/21659637/sudo -no-tty-present-and-no-askpass-program-specified-netbeans – uncletall

回答

2

问题是您的脚本在某个时候使用了sudo。通常的解决方法是添加脚本,要求您使用sudo到sudoers。

示例:在您的脚本中使用sudo service apache2 reload,现在创建一个包含该行的bash脚本并将该脚本添加到sudoers文件中。

新脚本名称:/home/quaser/restart-apache.sh

用途:visudo

添加到文件底部:现在

jenkins ALL=(ALL) NOPASSWD: /home/quaser/restart-apache.sh 

,在您的脚本变化:sudo service apache restartsudo /home/quaser/restart-apache.sh你不应该问为密码。

+0

谢谢@uncletall,明白了。 –

2

我有同样的问题,我解决了通过/etc/sudoers

cat /etc/sudoers| grep tty 
#Defaults requiretty 

评论Defaults requiretty从手册页:

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.