7

我刚刚配置了 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

我用谷歌搜索并在 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
4

3 回答 3

3

The "no tty present" error indicates that you have the 'requiretty' setting in your sudoers file. In your case, it is probably in /etc/sudoers.d. Once this line is there, it does not matter what group you are in - sudo will require a tty whenever it is executed.

To get around this, you need to either remove (or comment out) the requiretty line in the configuration file, or add a line to exclude your user from the requiretty setting. You can see how to do that here: Disable requiretty per user

于 2013-05-11T20:31:28.147 回答
3

通过添加以下内容: Defaults:username !authenticate 到您的 /etc/sudoers 您应该不会收到错误,但是无需输入密码即可访问此用户名

于 2013-09-17T12:13:05.660 回答
1

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

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

于 2013-05-07T10:55:20.120 回答