2014-06-30 285 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.