如何访问 Hudson 的“控制台输出”?
我有一个在 Hudson 构建系统下运行的构建 bash 脚本,它会写入自己的日志文件。但是,Hudson 捕获它执行的构建脚本的所有 stdout 和 stderr,并将其显示为构建的“控制台输出”。此外,此输出保存在构建历史记录中。
如何从脚本本身访问此“控制台输出”?我想 1)将其与工件一起保存为日志; 2) 将其附加到通知电子邮件中。谢谢
I have a build bash script running under Hudson build system, which writes its own log file. However, Hudson captures all the stdout and stderr of the build script it executes and displays it as the "console output" of the build. Furthermore, this output is saved in the build history.
How can I access this "console output" from within the script itself? I'd like to 1) save it as log together with the artifacts; 2) attach it to the notification email. Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
log
文件,即jobs/
jobname/builds/
buildid/log
)。如果您需要在其他地方获取它,有两种选择:
您可以将脚本包装在一个块中,并通过 tee 传输它的输出。所以你会转换:
<前><代码>#!/bin/sh
做这个
做到这一点
至:
<前><代码>#!/bin/bash
{
做这个
做到这一点
} 2>&1 |三通输出
# 现在输出位于文件“output”中,而 Hudson 确实看到了它。
不幸的是,我不确定如何在
tee
中强制行缓冲,以便实时日志打印在 Hudson 中工作(至少我的 cygwin 版本没有提到-u
选项)。您可以使用 Groovy 插件 和/或 Groovy Postbuild 插件 用于访问内部 API。构建步骤中的“系统”groovy 脚本和构建后的 groovy 脚本都可以访问 hudson.model.AbstractBuild ,您可以使用 hudson.model.AbstractBuild 获取控制台的内容。 org/hudson/model/Run.html#getLog(int)" rel="nofollow">hudson.model.Run#getLog(int) 方法。
log
file in top-level of build's directory, i.e.jobs/
jobname/builds/
buildid/log
).If you need to get it anywhere else, there are two options:
You can have to wrap the script in a block and pipe it's output through tee. So you'd convert:
to:
Unfortunately I am not sure how to force line-buffering in
tee
so the real-time log printing works in Hudson (at least my cygwin version does not mention-u
option).You could use the Groovy plugin and/or Groovy Postbuild plugin to access the internal API. The "system" groovy script in build step and the post-build groovy script both have access to the build object (though in slightly different way) of type hudson.model.AbstractBuild and from that you can get the content of the console using the hudson.model.Run#getLog(int) method.
要在 tee 中强制行缓冲,只需使用
unbuffer {command}
启动程序,它是expect
包的一部分。unbuffer
的另一种替代方法是使用stdbuf -eL -oL {command}
To force line-buffering in tee, just start the program with
unbuffer {command}
which is part of theexpect
package. Another alternative tounbuffer
is to usestdbuf -eL -oL {command}