问题描述:
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