【发布时间】:2013-09-26 04:24:44
【问题描述】:
我正在使用 jenkins 运行我的构建。
我的步骤之一是复制某些文件并使用 sudo 将它们放在 /etc/init 中
<exec command="ssh -A ${host-used} '/etc/init.d/ConvertDaemon stop'" outputProperty="result" escape="false">
</exec>
<echo msg="${result}" />
<exec command="ssh -A ${host-used} 'sudo Console/cake init_runners copy_runners_into_initd'" outputProperty="result" escape="false" />
<echo msg="${result}" />
${host-used} returns www-data@ip-address
问题是第二个命令。
当我运行第一个命令时,我可以在 jenkins 的控制台日志中看到我的结果。
对于第二个命令,我收到 no tty present 消息
所以我将第二个命令更改为
<exec command="ssh -t ${host-used} -A ${host-used} 'sudo Console/cake init_runners copy_runners_into_initd'" outputProperty="result" escape="false" />
<echo msg="${result}" />
我得到一个
Pseudo-terminal will not be allocated because stdin is not a terminal
我该如何克服这个问题?
更新:
我也试过这个。
<exec command="ssh -t -t ${host-used} -A ${host-used} 'sudo Console/cake init_runners copy_runners_into_initd'" outputProperty="result" escape="false" />
<echo msg="${result}" />
我明白了:
bash: www-data@ipaddress: command not found
Connection to ipaddress closed.
我想强调的是,该命令使用正确。但我无法阅读该消息。
更新 2:
有时你会问一个问题,但随后你会意识到你想问的问题并不是你想解决的REAL问题。
这个问题是这样的。
我想要做的就是执行一些由 jenkins 运行的命令并查看命令的打印输出。这些命令恰好需要 sudo。
Jenkins 基本上 ssh 作为另一个用户 www-data 来执行这些命令。
对于需要 sudo 的命令,我无法在 jenkins 中打印结果。
在度过了一个愉快的星期六并提供了一些非常有用的 SO 答案后,我意识到我可以简单地尝试在不使用 sudo 的情况下执行这些命令,而是让 jenkins ssh 作为 root。
成功了。
我将用这种方法来回答这个问题,因为这就是我想要的——在 jenkins 中执行一些命令并查看它们的打印输出。
【问题讨论】:
-
看起来你可能需要在你的 ssh 命令上添加一个额外的 -t 参数,根据这个问题的答案:stackoverflow.com/questions/7114990/…
-
我试过了。它失败了。更新了我的问题,@AaronGolden