問題描述:
jenkins執行發布腳本,因為使用的是jenkins用戶,所以有些shell命令需要 sudo 來執行,導致報錯。
+ sudo rm -rf /usr/share/nginx/html/jenkins_test.bak
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.
sudo: no tty present and no askpass program specified
解決辦法:
編輯 '/etc/sudoers' 文件,因為沒有編輯權限,需要增加權限
chmod u+w /etc/sudoers
進入編輯模式,找到
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
在下面加入一行,jenkins換成要使用 sudo 命令的用戶
jenkins ALL=(ALL) ALL
然后保存,退出,恢復文件的權限
chmod u-w /etc/sudoers