Jenkins 控制台输出不是实时的 [英] Jenkins console output not in realtime

查看:44
本文介绍了Jenkins 控制台输出不是实时的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对 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

推荐答案

澄清一些答案.

  • rubypython 或任何合理的脚本语言将缓冲输出;这是为了最小化 IO;写入磁盘很慢,写入控制台很慢...
  • 通常在缓冲区中有足够的数据并对换行符进行特殊处理后,数据会自动flush().例如写一个没有换行符的字符串然后 sleep()sleep() 完成之前不会写任何东西(我只使用 sleep 作为例如,您可以随意替换为任何其他昂贵的系统调用).
  • ruby or python 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 then sleep() would not write anything until after the sleep() is complete (I'm only using sleep 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()

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆