Jenkins console output not in realtime

后端 未结 9 1012
失恋的感觉
失恋的感觉 2020-12-13 06:14

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.

Problem is Je

相关标签:
9条回答
  • 2020-12-13 06:37

    The Operating-System is buffering output-data by nature, to save CPU, and so does Jenkins.

    Looks like you are using a shell-command to run your Ruby script -
    I suggest running your Ruby script directly via the dedicated plugin:

    Jenkins Ruby Plugin

    (may need to install it)

    0 讨论(0)
  • 2020-12-13 06:40

    Easiest solution here is to turn on syncing buffer to output. Something that @Craig wrote about in his answer but one line solution that will cover whole script, and not require you to flush buffer many times.

    Just write

    STDOUT.sync = true
    

    Logic behind is simple, to avoid using IO operations many times output is buffered. To disable this use

    STDOUT.sync = false
    

    This is Ruby solution ofc.

    0 讨论(0)
  • 2020-12-13 06:42

    For some commands, including tee a the best choice for unbuffering is a program called unbuffer from expect package.

    Usage example:

    instead of

    somecommand | tee /some/path

    do

    somecommand | unbuffer -p tee /some/path

    Sources and more info:

    • https://stackoverflow.com/a/11337310/2693875
    • https://unix.stackexchange.com/a/25375/53245
    0 讨论(0)
  • 2020-12-13 06:45

    Make sure your script is flushing its stdout and stderr. In my case I had a buffering issue similar to what you describe but I was using python. The following python code fixed it for me:

    import sys
    sys.stdout.flush()
    

    I'm not a Ruby coder, but Google reveals the following:

    $stdout.flush
    
    0 讨论(0)
  • 2020-12-13 06:47

    It seems to me that python -u works as well.

    E.g. In batch command

    python -u foo.py
    
    0 讨论(0)
  • 2020-12-13 06:48

    The other answers are correct in saying that you need to ensure standard output is not buffered.

    The other thing to be aware of is that Jenkins itself does line by line buffering. If you have a slow-running process that emits single characters (for example, an nunit test suite summary that prints a . for a successful test and an E for an error) you will not see anything until the end of line.

    [True for my Jenkins 1.572 running on a Windows box.]

    0 讨论(0)
提交回复
热议问题