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

bat pipeline with returnstdout=true echos command

      We updated to Jenkins LTS 2.401.1 via dockerhub. Since that version all our pipeline builds broke because the bat pipeline step seems to also return the command call itself in the result which it did not before. Powershell works.

       

      See the following code to reproduce the problem

      stage('Test') {
        steps {
          script {
            def result = bat(label: '', returnStdout: true, script: 'echo echotestresponse')
            echo "output from bat: $result"
            def psResult = powershell(label: '', returnStdout: true, script: 'echo echotestresponse')
            echo "output from powershell: $psResult"
          }
        }
      }

      Output is:

      17:17:18  [Pipeline] stage
      17:17:18  [Pipeline] { (Test)
      17:17:18  [Pipeline] script
      17:17:18  [Pipeline] {
      17:17:18  [Pipeline] bat
      17:17:18  [Pipeline] echo
      17:17:18  output from bat: 
      17:17:18  jenkins@HMJENKINS4 d:\jenkins\workspace\MPA_jenkins-fixing>echo echotestresponse 
      17:17:18  echotestresponse
      17:17:18  
      17:17:18  [Pipeline] powershell
      17:17:19  [Pipeline] echo
      17:17:19  output from powershell: echotestresponse
      17:17:19  
      17:17:19  [Pipeline] }
      17:17:19  [Pipeline] // script
      17:17:19  [Pipeline] }
      17:17:19  [Pipeline] // stage 

      Additionally there is also a new line character at start of the result now.

       

      A workaround seems to be to prefix any command with @ or @echo off explicitely.

          [JENKINS-71436] bat pipeline with returnstdout=true echos command

          Daniel created issue -
          Daniel made changes -
          Summary Original: bat pipeline step does not return stdout anymore New: bat pipeline step does not return stdout anymore with returnstdout=true
          Daniel made changes -
          Priority Original: Minor [ 4 ] New: Critical [ 2 ]
          Daniel made changes -
          Description Original: We updated to Jenkins LTS 2.401.1 via dockerhub. Since that version the bat pipeline step seems to be broken and does not return stdout anymore. The same code with powershell works.

           

          See the following code to reproduce the problem
          {code:java}
          stage('Test') {
            steps {
              script {
                def result = bat(label: '', returnStdout: true, script: 'echo echotest response')
                echo "output from bat: $result"

                def psResult = powershell(label: '', returnStdout: true, script: 'echo echotest response')
                echo "output from powershell: $psResult"
              }
            }
          } {code}
          Output is:

           
          {code:java}
          16:56:23 [Pipeline] stage
          16:56:23 [Pipeline] { (Test)
          16:56:23 [Pipeline] script
          16:56:23 [Pipeline] {
          16:56:23 [Pipeline] bat
          16:56:23 [Pipeline] echo
          16:56:23 output from bat:
          16:56:23 jenkins@HMJENKINS4 d:\jenkins\workspace\MPA_jenkins-fixing>echo echotest response
          16:56:23 echotest response
          16:56:23
          16:56:23 [Pipeline] powershell
          16:56:24 [Pipeline] echo
          16:56:24 output from powershell: echotest
          16:56:24 response
          16:56:24
          16:56:24 [Pipeline] }
          16:56:24 [Pipeline] // script
          16:56:24 [Pipeline] }
          16:56:24 [Pipeline] // stage
           {code}
           

          Variable is not set with output from stdout in bat step. See "output from bat:"

           
          New: We updated to Jenkins LTS 2.401.1 via dockerhub. Since that version all our pipeline builds are broken because the bat pipeline step seems to not return stdout anymore. The same code with powershell works.

           

          See the following code to reproduce the problem
          {code:java}
          stage('Test') {
            steps {
              script {
                def result = bat(label: '', returnStdout: true, script: 'echo echotest response')
                echo "output from bat: $result"

                def psResult = powershell(label: '', returnStdout: true, script: 'echo echotest response')
                echo "output from powershell: $psResult"
              }
            }
          } {code}
          Output is:

           
          {code:java}
          16:56:23 [Pipeline] stage
          16:56:23 [Pipeline] { (Test)
          16:56:23 [Pipeline] script
          16:56:23 [Pipeline] {
          16:56:23 [Pipeline] bat
          16:56:23 [Pipeline] echo
          16:56:23 output from bat:
          16:56:23 jenkins@HMJENKINS4 d:\jenkins\workspace\MPA_jenkins-fixing>echo echotest response
          16:56:23 echotest response
          16:56:23
          16:56:23 [Pipeline] powershell
          16:56:24 [Pipeline] echo
          16:56:24 output from powershell: echotest
          16:56:24 response
          16:56:24
          16:56:24 [Pipeline] }
          16:56:24 [Pipeline] // script
          16:56:24 [Pipeline] }
          16:56:24 [Pipeline] // stage
           {code}
           

          Variable is not set with output from stdout in bat step. See "output from bat:"

           

          Markus Winter added a comment - - edited

          But the output is there. This is the output:

          16:56:23  jenkins@HMJENKINS4 d:\jenkins\workspace\MPA_jenkins-fixing>echo echotest response 
          16:56:23  echotest response
          

          Markus Winter added a comment - - edited But the output is there. This is the output: 16:56:23 jenkins@HMJENKINS4 d:\jenkins\workspace\MPA_jenkins-fixing>echo echotest response 16:56:23 echotest response

          Daniel added a comment -

          Yes the output is there, but not returned and assigned to the variable. That is the problem.

          We use it to get some infos from maven command like the pom version.

          Daniel added a comment - Yes the output is there, but not returned and assigned to the variable. That is the problem. We use it to get some infos from maven command like the pom version.
          Daniel made changes -
          Description Original: We updated to Jenkins LTS 2.401.1 via dockerhub. Since that version all our pipeline builds are broken because the bat pipeline step seems to not return stdout anymore. The same code with powershell works.

           

          See the following code to reproduce the problem
          {code:java}
          stage('Test') {
            steps {
              script {
                def result = bat(label: '', returnStdout: true, script: 'echo echotest response')
                echo "output from bat: $result"

                def psResult = powershell(label: '', returnStdout: true, script: 'echo echotest response')
                echo "output from powershell: $psResult"
              }
            }
          } {code}
          Output is:

           
          {code:java}
          16:56:23 [Pipeline] stage
          16:56:23 [Pipeline] { (Test)
          16:56:23 [Pipeline] script
          16:56:23 [Pipeline] {
          16:56:23 [Pipeline] bat
          16:56:23 [Pipeline] echo
          16:56:23 output from bat:
          16:56:23 jenkins@HMJENKINS4 d:\jenkins\workspace\MPA_jenkins-fixing>echo echotest response
          16:56:23 echotest response
          16:56:23
          16:56:23 [Pipeline] powershell
          16:56:24 [Pipeline] echo
          16:56:24 output from powershell: echotest
          16:56:24 response
          16:56:24
          16:56:24 [Pipeline] }
          16:56:24 [Pipeline] // script
          16:56:24 [Pipeline] }
          16:56:24 [Pipeline] // stage
           {code}
           

          Variable is not set with output from stdout in bat step. See "output from bat:"

           
          New: We updated to Jenkins LTS 2.401.1 via dockerhub. Since that version all our pipeline builds are broken because the bat pipeline step seems to not return stdout anymore. The same code with powershell works.

           

          See the following code to reproduce the problem
          {code:java}
          stage('Test') {
            steps {
              script {
                def result = bat(label: '', returnStdout: true, script: 'echo echotestresponse')
                echo "output from bat: $result"
                def psResult = powershell(label: '', returnStdout: true, script: 'echo echotestresponse')
                echo "output from powershell: $psResult"
              }
            }
          }{code}
          Output is:
          {code:java}
          17:17:18 [Pipeline] stage
          17:17:18 [Pipeline] { (Test)
          17:17:18 [Pipeline] script
          17:17:18 [Pipeline] {
          17:17:18 [Pipeline] bat
          17:17:18 [Pipeline] echo
          17:17:18 output from bat:
          17:17:18 jenkins@HMJENKINS4 d:\jenkins\workspace\MPA_jenkins-fixing>echo echotestresponse
          17:17:18 echotestresponse
          17:17:18
          17:17:18 [Pipeline] powershell
          17:17:19 [Pipeline] echo
          17:17:19 output from powershell: echotestresponse
          17:17:19
          17:17:19 [Pipeline] }
          17:17:19 [Pipeline] // script
          17:17:19 [Pipeline] }
          17:17:19 [Pipeline] // stage {code}
          Variable is not set with output from stdout in bat step. See "output from bat:"

           

          Markus Winter added a comment -

          The variable must be set otherwise the output wouldn't appear after the text 

          output from bat:
          

          If this was the output of the step itself would have to appear before that line

          Markus Winter added a comment - The variable must be set otherwise the output wouldn't appear after the text  output from bat: If this was the output of the step itself would have to appear before that line

          Daniel added a comment -

          I have seen the same and it confused me too. So I added a sleep between the echo and the bat execution.

          See the output:

          17:51:28  [Pipeline] stage
          17:51:28  [Pipeline] { (Test)
          17:51:28  [Pipeline] script
          17:51:28  [Pipeline] {
          17:51:28  [Pipeline] bat
          17:51:28  [Pipeline] sleep
          17:51:28  Sleeping for 5 sec
          17:51:33  [Pipeline] echo
          17:51:33  output from bat: 
          17:51:33  jenkins@HMJENKINS4 d:\jenkins\workspace\MPA_jenkins-fixing>echo echotestresponse 
          17:51:33  echotestresponse
          17:51:33  
          17:51:33  [Pipeline] powershell
          17:51:34  [Pipeline] echo
          17:51:34  output from powershell: echotestresponse
          17:51:34  
          17:51:34  [Pipeline] }
          17:51:34  [Pipeline] // script
          17:51:34  [Pipeline] }
          17:51:34  [Pipeline] // stage 

          Code

          stage('Test') {
            steps {
              script {
                def result = bat(label: '', returnStdout: true, script: 'echo echotestresponse')
                sleep(time:5, unit:"SECONDS")
                echo "output from bat: $result"
                def psResult = powershell(label: '', returnStdout: true, script: 'echo echotestresponse')
                echo "output from powershell: $psResult"
              }
            }
          } 

           

          Daniel added a comment - I have seen the same and it confused me too. So I added a sleep between the echo and the bat execution. See the output: 17:51:28 [Pipeline] stage 17:51:28 [Pipeline] { (Test) 17:51:28 [Pipeline] script 17:51:28 [Pipeline] { 17:51:28 [Pipeline] bat 17:51:28 [Pipeline] sleep 17:51:28 Sleeping for 5 sec 17:51:33 [Pipeline] echo 17:51:33 output from bat: 17:51:33 jenkins@HMJENKINS4 d:\jenkins\workspace\MPA_jenkins-fixing>echo echotestresponse 17:51:33 echotestresponse 17:51:33 17:51:33 [Pipeline] powershell 17:51:34 [Pipeline] echo 17:51:34 output from powershell: echotestresponse 17:51:34 17:51:34 [Pipeline] } 17:51:34 [Pipeline] // script 17:51:34 [Pipeline] } 17:51:34 [Pipeline] // stage Code stage( 'Test' ) { steps { script { def result = bat(label: '', returnStdout: true , script: ' echo echotestresponse') sleep(time:5, unit: "SECONDS" ) echo "output from bat: $result" def psResult = powershell(label: '', returnStdout: true , script: ' echo echotestresponse') echo "output from powershell: $psResult" } } }  
          Daniel made changes -
          Component/s Original: batch-task-plugin [ 15505 ]

            Unassigned Unassigned
            dko Daniel
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: