Jenkins 控制台输出不是实时的 [英] Jenkins console output not in realtime
问题描述
对 Jenkins 来说很新,我有一个简单但烦人的问题.当我在 Jenkins 上运行作业 (Build) 时,我触发了 ruby 命令来执行我的测试脚本.
Pretty new to Jenkins and I have simple yet annoying problem. When I run job (Build) on Jenkins I am triggering ruby command to execute my test script.
问题是 Jenkins 没有从控制台实时显示输出.这是触发日志.
Problem is Jenkins is not displaying output in real time from console. Here is trigger log.
Building in workspace /var/lib/jenkins/workspace/foo_bar
No emails were triggered.
[foo_bar] $ /bin/sh -xe /tmp/hudson4042436272524123595.sh
+ ruby /var/lib/jenkins/test-script.rb
基本上它会挂在这个输出上,直到构建完成,而不是只显示完整的输出.有趣的是,这不是一致的行为,有时它可以正常工作.但大多数时候没有实时控制台输出.
Basically it hangs on this output until build is complete than it just shows full output. Funny thing is this is not consistent behavior, sometimes it works as it should. But most of the time there is no real time console output.
詹金斯版本:1.461
Jenkins version: 1.461
推荐答案
澄清一些答案.
ruby
或python
或任何合理的脚本语言将缓冲输出;这是为了最小化 IO;写入磁盘很慢,写入控制台很慢...- 通常在缓冲区中有足够的数据并对换行符进行特殊处理后,数据会自动
flush()
.例如写一个没有换行符的字符串然后sleep()
在sleep()
完成之前不会写任何东西(我只使用sleep
作为例如,您可以随意替换为任何其他昂贵的系统调用).
ruby
orpython
or any sensible scripting language will buffer the output; this is in order to minimize the IO; writing to disk is slow, writing to a console is slow...- usually the data gets
flush()
'ed automatically after you have enough data in the buffer with special handling for newlines. e.g. writing a string without newline thensleep()
would not write anything until after thesleep()
is complete (I'm only usingsleep
as an example, feel free to substitute with any other expensive system call).
例如这将等待 8 秒,打印一行,再等 5 秒,打印第二行.
e.g. this would wait 8 seconds, print one line, wait 5 more seconds, print a second line.
from time import sleep
def test():
print "ok",
time.sleep(3)
print "now",
time.sleep(5)
print "done"
time.sleep(5)
print "again"
test()
对于
ruby
,STDOUT.sync = true
,打开autoflush
;所有对STDOUT
的写入后跟flush()
.这将解决您的问题,但会导致更多 IO.for
ruby
,STDOUT.sync = true
, turns theautoflush
on; all writes toSTDOUT
are followed byflush()
. This would solve your problem but result in more IO.STDOUT.sync = true
对于
python
,您可以使用python -u
或环境变量PYTHONUNBUFFERED
来制作stdin/stdout/粗壮
没有缓冲,但还有其他解决方案不会改变stdin
或stderr
for
python
, you can usepython -u
or the environment variablePYTHONUNBUFFERED
to makestdin/stdout/stout
not buffered, but there are other solutions that do not changestdin
orstderr
export PYTHONUNBUFFERED=1
对于
perl
,你有autoflush
一个>autoflush STDOUT 1;
这篇关于Jenkins 控制台输出不是实时的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!