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

extra newline character from powershell output

    Details

    • Similar Issues:

      Description

      When i trying to wrap some powershell script output into variable, it's adds excess \n symbol to.

      Like:

      script {
      	VARI = powershell (returnStdout: true, script: """Write-Output foo""")
      	println VARI
      	}
      

      It's outputs the following:

      [Pipeline] script
      [Pipeline] {
      [Pipeline] powershell
      [Pipeline] echo
      foo
      
      [Pipeline] }
      [Pipeline] // script
      [Pipeline] }
      

      But powershell itself transmits output without `n .
      How to escape it in output?

        Attachments

          Activity

          Hide
          jameswithers James Withers added a comment -

          I believe this is a feature of Powershell's Write-*. You can add -NoNewLine as a parameter.

           

          Show
          jameswithers James Withers added a comment - I believe this is a feature of Powershell's Write-*. You can add -NoNewLine as a parameter.  
          Hide
          gek gek added a comment - - edited

          But how?

          Only way i see is use Write-Host -NoNewline , but it's output cannot be passed thru:

           

          https://serverfault.com/questions/859826/output-is-truncated-in-jenkins-job-when-launching-powershell-script-remotely-usi

           

          For some reason Write-Host -NoNewline output cannot be assigned to variable.

          Show
          gek gek added a comment - - edited But how? Only way i see is use Write-Host -NoNewline , but it's output cannot be passed thru:   https://serverfault.com/questions/859826/output-is-truncated-in-jenkins-job-when-launching-powershell-script-remotely-usi   For some reason Write-Host -NoNewline output cannot be assigned to variable.
          Hide
          patrike Patrik Ehringer added a comment - - edited

           

          Maybe this is related...

          The console output is different for the 2 scripts below - depending on if 'returnStdout: true' is used or not.
          The second script does it right, the first - where 'returnStdout: true' is used - does it wrong.
          I'm quite sure that the first script also worked correctly 2 months or so ago.

          pipeline {
              agent any
              stages {
                  stage('Test') {
                      steps  {
                          script {
                              stdo = powershell(returnStdout: true, script: '''
                                  Write-Host "Will there be a newline after me? " -NoNewLine
                                  Write-Host "Yes! -> Unfortunately!"
                              ''')
                          }
                          script {
                              powershell(script: '''
                                  Write-Host "Will there be a newline after me? " -NoNewLine
                                  Write-Host "No! -> Great!"
                              ''')
                          }
                      }
                  }
              }
          }
          
          

           

          [Pipeline] {
          [Pipeline] stage
          [Pipeline] { (Test)
          [Pipeline] script
          [Pipeline] {
          [Pipeline] powershell
          Will there be a newline after me? 
          Yes! -> Unfortunately!
          [Pipeline] }
          [Pipeline] // script
          [Pipeline] script
          [Pipeline] {
          [Pipeline] powershell
          Will there be a newline after me? No! -> Great!
          [Pipeline] }
          [Pipeline] // script
          [Pipeline] }
          [Pipeline] // stage
          [Pipeline] }
          [Pipeline] // node
          [Pipeline] End of Pipeline
          Finished: SUCCESS

           

          Show
          patrike Patrik Ehringer added a comment - - edited   Maybe this is related... The console output is different for the 2 scripts below - depending on if 'returnStdout: true' is used or not. The second script does it right, the first - where 'returnStdout: true' is used - does it wrong. I'm quite sure that the first script also worked correctly 2 months or so ago. pipeline { agent any stages { stage( 'Test' ) { steps { script { stdo = powershell(returnStdout: true , script: ''' Write-Host "Will there be a newline after me? " -NoNewLine Write-Host "Yes! -> Unfortunately!" ''') } script { powershell(script: ''' Write-Host "Will there be a newline after me? " -NoNewLine Write-Host "No! -> Great!" ''') } } } } }   [Pipeline] { [Pipeline] stage [Pipeline] { (Test) [Pipeline] script [Pipeline] { [Pipeline] powershell Will there be a newline after me? Yes! -> Unfortunately! [Pipeline] } [Pipeline] // script [Pipeline] script [Pipeline] { [Pipeline] powershell Will there be a newline after me? No! -> Great! [Pipeline] } [Pipeline] // script [Pipeline] } [Pipeline] // stage [Pipeline] } [Pipeline] // node [Pipeline] End of Pipeline Finished: SUCCESS  

            People

            • Assignee:
              gek gek
              Reporter:
              gek gek
            • Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated: