jenkins在重新启动我的sql时失败了"sudo:没有tty存在且没有指定askpass程序抱歉,请再试一次."

Rag*_*ngh 5 mysql amazon-web-services jenkins

我刚刚配置了jenkins,并且在预构建步骤中我试图重新启动jenkins但我最终得到以下错误

Commencing build of Revision c5b9f8daac092efc5396d80f568a2cf89ae8b697 (origin/HEAD, origin/master)
Checking out Revision c5b9f8daac092efc5396d80f568a2cf89ae8b697 (origin/HEAD, origin/master)
No change to record in branch origin/HEAD
No change to record in branch origin/master
[webapp] $ /bin/sh -xe /tmp/hudson5215632082686866774.sh
+ sudo /etc/init.d/mysql restart
sudo: no tty present and no askpass program specified
Sorry, try again.
sudo: no tty present and no askpass program specified
Sorry, try again.
sudo: no tty present and no askpass program specified
Sorry, try again.
sudo: 3 incorrect password attempts
Build step 'Execute shell' marked build as failure
Finished: FAILURE
Run Code Online (Sandbox Code Playgroud)

我用Google搜索并在Jenkins看到了一些答案,因为sudo无法启动:没有tty存在且没有指定askpass程序

但不幸的是,这对我没有帮助

我的/ etc/sudoers看起来像这样

#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults        env_reset
Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root    ALL=(ALL:ALL) ALL

# Members of the admin group may gain root privileges
%admin ALL=(ALL) NOPASSWD: ALL

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d
Run Code Online (Sandbox Code Playgroud)

小智 1

请使用“id”命令并粘贴输出。仅当您在管理员组中时,您才不需要密码,但对于所有其他组,即使您有访问权限,但需要输入 sudo 密码。在这种情况下, sudo 没有 tty 来询问密码,因此会出现错误。

一种解决方案可能是,不要仅将 sudo 用于 mysql 重新启动,而是将整个脚本运行为 sudo "sudo {your script path}" 在这种情况下,sudo 将让终端询问密码。