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

extra newline character from powershell output

      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?

          [JENKINS-56925] extra newline character from powershell output

          James Withers added a comment -

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

           

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

          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.

          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.

          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

           

          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  

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

              Created:
              Updated: