Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-63504

parallel tee sh garbles output

    XMLWordPrintable

Details

    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 "
                                              }

       

      Attachments

        Activity

          jamessassano James Sassano added a comment -

          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.

           

          jamessassano James Sassano added a comment - 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.  

          People

            rsandell rsandell
            jamessassano James Sassano
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: