gpt4 book ai didi

continuous-integration - Jenkins 控制台输出不是实时的

转载 作者:行者123 更新时间:2023-12-04 08:24:51 25 4
gpt4 key购买 nike

Jenkins 很新,我有简单但烦人的问题。当我在 Jenkins 上运行作业(构建)时,我触发了 ruby​​ 命令来执行我的测试脚本。

问题是 Jenkins 没有从控制台实时显示输出。这是触发日志。

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

基本上它会卡在这个输出上,直到构建完成,而不是只显示完整的输出。有趣的是,这不是一致的行为,有时它可以正常工作。但大多数时候没有实时控制台输出。

Jenkins 版本:1.461

最佳答案

澄清一些答案。

  • rubypython或者任何合理的脚本语言都会缓冲输出;这是为了最小化 IO;写入磁盘很慢,写入控制台很慢...
  • 通常数据得到flush() 'ed 在缓冲区中有足够的数据后自动进行,并对换行符进行特殊处理。例如写一个没有换行符的字符串然后 sleep()直到 sleep() 之后才会写任何东西已完成(我仅使用 sleep 作为示例,请随意替换为任何其他昂贵的系统调用)。

  • 例如这将等待 8 秒,打印一行,再等 5 秒,打印第二行。
    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。
    STDOUT.sync = true
  • python ,您可以使用 python -u或环境变量 PYTHONUNBUFFERED制作 stdin/stdout/stout没有缓冲,但 there are other solutions不变的stdinstderr
    export PYTHONUNBUFFERED=1
  • perl , 你有 autoflush
    autoflush STDOUT 1;
  • 关于continuous-integration - Jenkins 控制台输出不是实时的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11631951/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com