繁体   English   中英

Jenkins sudo:没有 tty,也没有用 NOPASSWD 指定的 askpass 程序 [重复]

[英]Jenkins sudo: no tty present and no askpass program specified with NOPASSWD [duplicate]

我花了几天时间设置文件/etc/sudoers以便能够向用户jenkins授予 root 权限。 我在我的服务器上安装了 Jenkins,因为我用 symfony、ionic、neo4j 等托管了几个项目......问题是我不能用 ionic 在项目中构建,我收到这个错误: sudo: no tty present and no askpass program specified. 这是我的 /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    mail_badpass
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
jenkins ALL=(ALL) NOPASSWD: ALL
# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

我已经在问题的评论中测试了@Jayan 描述的解决方案。 您必须在文件末尾包含新行:

解决方案: https : //stackoverflow.com/a/24648413/54506

#
# 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    mail_badpass
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

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

这只是对详细说明解决问题的步骤的回应。

首先,弄清楚 Jenkins GUI 正在使用哪个用户来执行 bash shell 脚本。

选择项目 > 配置 > 在可执行 shell 中输入whoami > 保存并立即构建。 在此处输入图片说明 在构建历史记录中查看结果 > 单击控制台输出

用户可能是 tomcat 或 jenkins 或其他什么。

SSH 到 Jenkins 服务器

  1. sudo su
  2. visudo
  3. tomcat ALL=(ALL) NOPASSWD: ALL #如果显示的用户是tomcat 在此处输入图片说明

这很可能是您在 sudoers 文件中添加了错误的用户。 这也发生在我身上,在 sudoers 文件中添加条目的解决方案对我不起作用。 您需要知道 jenkins 用来执行命令的实际用户。 为此,您可以使用以下命令在 jenkins 中添加构建步骤(执行 shell):

whoami

然后再次尝试运行 jenkins 作业,在控制台输出中,您将看到 jenkins 用于执行命令的用户。 然后,您需要将此用户添加到您的 sudoers 文件中。 例如,如果用户是 'tomcat',您将以下行添加到 sudoers 文件的末尾:

tomcat ALL=(ALL) NOPASSWD: ALL

参考: http : //techrofile.com/jenkins-sudo-no-tty-present-and-no-askpass-program-specified-with-nopasswd/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM