3

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.

Roman
  • 4,531
  • 10
  • 40
  • 69

3 Answers3

3

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

CrazyCoder
  • 389,263
  • 172
  • 990
  • 904
1

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.

Alexander Sulfrian
  • 3,533
  • 1
  • 16
  • 9
  • Yes, it's a good suggestion to use TeamCity specific messages. – CrazyCoder Sep 13 '11 at 15:31
  • Unfortunately I cannot use TeamCity messages because I don't want rewrite my Python scripts and replace messages to stderr with TeamCity messages (some scripts are third-party) – Roman Sep 17 '11 at 21:16
0

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
    "${'$'}@"
    local exit_code=${'$'}?
    sleep 0.1 # synchronize stdout and stderr for TeamCity
    return ${'$'}exit_code
  )
}

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.

Sergey
  • 1,552
  • 20
  • 18