Details
-
Bug
-
Status: Open (View Workflow)
-
Minor
-
Resolution: Unresolved
-
None
Description
When running the tee command on parallel stages the console output becomes garbled. The stage name is displayed directly over other stage names, and output is mangled together.
pipeline { agent any stages { stage('stage') { steps { script { parallel ((1..20).collect{it}.collectEntries {stageNumber -> ["$stageNumber": { node('master') { stage("$stageNumber") { tee('output.log') { sh("for i in 1 2 3 4 5; do sleep 1; echo $stageNumber \$i; done") } } } }] }) } } } } }
Will produce console output such as:
...
+ for i in 1 23 3 4 5
+ 4s l5e
e+p 3s
leep 3
++ e cehcoh o5 62
25
62 2+ +f ofro ri ii ni n1 12 23 34 455
...
However, this behaves nominally if the tee block does not call sh:
[1, 2, 3, 4, 5].each {
sleep 1
echo "$stageNumber $it "
}
For a POSIX compliant workaround, this seems to work for me:
sh(returnStatus: true, script: """#!/bin/sh { { { { (set -xe; $script) 2>&1; echo \$? >&3; } | tee $output >&4; } 3>&1; } | { read xs; exit \$xs; } } 4>&1 """)
See:
https://unix.stackexchange.com/questions/14270/get-exit-status-of-process-thats-piped-to-another
But I additionally wrapped the script with an internal set -xe, and redirected the script's stderr to stdout.