TeamCity:写入 stderr 和 stdout 时构建日志中的消息顺序错误

发布于 2024-12-04 14:33:21 字数 286 浏览 0 评论 0原文

简单的 python 脚本:

for i in range(0, 5):
  print "ok"
  sys.stderr.write('err\r\n')

在 TeamCity 下执行此脚本(构建步骤)时,“构建日志”选项卡中会出现以下输出:

ok
err
ok
ok
ok
err
ok
err
err
err

消息完全随机顺序错误。

请建议如何使消息按照写入输出的顺序进行。

谢谢。

Simple python script:

for i in range(0, 5):
  print "ok"
  sys.stderr.write('err\r\n')

When executing this script under TeamCity (build step), following output appears in Build Log tab:

ok
err
ok
ok
ok
err
ok
err
err
err

Messages go in wrong completely random order.

Please suggest how to make messages go in same order they are written to output.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

望她远 2024-12-11 14:33:21

这是一个已知问题,请加注星标/投票。

It's a known issue, please star/vote.

梨涡少年 2024-12-11 14:33:21

如果您只想写入 stdout 和 stderr 来区分消息和错误,您可以尝试使用服务消息: http://confluence.jetbrains.net/display/TCD65/Build+Script+Interaction+with+TeamCity。他们仅使用一种渠道来区分不同的消息,并且不会以错误的顺序传递。

If you only want to write to stdout and stderr to distinguish between messages and errors, you could try to use service messages: http://confluence.jetbrains.net/display/TCD65/Build+Script+Interaction+with+TeamCity. They are using only one channel to distinguish different messages and do not go in wrong order.

始终不够爱げ你 2024-12-11 14:33:21

以下是 bash 脚本的部分解决方法:

sync() {
  (
    { set +x; } 2> /dev/null # silently disable xtrace
    sleep 0.1 # synchronize stdout and stderr for TeamCity
    "${'

现在您至少可以在重要命令之前和之后同步 stdoutstderr

set -x
sync wget http://examples.com/
sync bash myscript.sh arg1 arg2

在此更改之前,TeamCity 可以在某些行之后显示打印的 bash 命令通过该命令打印。

}@" local exit_code=${'

现在您至少可以在重要命令之前和之后同步 stdoutstderr


在此更改之前,TeamCity 可以在某些行之后显示打印的 bash 命令通过该命令打印。

}? sleep 0.1 # synchronize stdout and stderr for TeamCity return ${'

现在您至少可以在重要命令之前和之后同步 stdoutstderr


在此更改之前,TeamCity 可以在某些行之后显示打印的 bash 命令通过该命令打印。

}exit_code ) }

现在您至少可以在重要命令之前和之后同步 stdoutstderr

在此更改之前,TeamCity 可以在某些行之后显示打印的 bash 命令通过该命令打印。

Here is a partial workaround for bash scripts:

sync() {
  (
    { set +x; } 2> /dev/null # silently disable xtrace
    sleep 0.1 # synchronize stdout and stderr for TeamCity
    "${'

Now you can synchronize stdout and stderr at least before and after important commands:

set -x
sync wget http://examples.com/
sync bash myscript.sh arg1 arg2

Before this change TeamCity could show printed bash command after some lines printed by this command.

}@" local exit_code=${'

Now you can synchronize stdout and stderr at least before and after important commands:


Before this change TeamCity could show printed bash command after some lines printed by this command.

}? sleep 0.1 # synchronize stdout and stderr for TeamCity return ${'

Now you can synchronize stdout and stderr at least before and after important commands:


Before this change TeamCity could show printed bash command after some lines printed by this command.

}exit_code ) }

Now you can synchronize stdout and stderr at least before and after important commands:

Before this change TeamCity could show printed bash command after some lines printed by this command.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文