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

Write-Error in powershell step behaves confusingly

      In the Release Notes for Powershell support, it is stated clearly, with an example, that writing to the error stream in powershell will fail that stage:

      Your powershell step may produce a failing exit status in the following instances:

      • Something in your PowerShell script has thrown an exception
      • Your PowerShell script explicitly calls exit with a non-zero exit code
      • Your PowerShell script calls a native application that produces a non-zero $LastExitCode
      • Your PowerShell script results in a non-empty error stream (with or without throwing an exception)

      However, if I try that myself, the stage succeeds (though error output is still written to the console):

      pipeline {
          agent { label 'windows' }
          options {
              skipDefaultCheckout()
              durabilityHint('PERFORMANCE_OPTIMIZED')
          }
          stages {
              stage('write-error') {
                  steps {
                      powershell 'write-error "bang"'
                  }
              }
          }
      }
      
      [write-error] powershell.exe : C:\Jenkins\workspace\owpos\pos\frp\00-build@tmp\durable-2fc4febd\powershellScript.ps1 : bang
      [write-error] At C:\Jenkins\workspace\owpos\pos\frp\00-build@tmp\durable-2fc4febd\powershellWrapper.ps1:3 char:1
      [write-error] + & powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass -Comm ...
      [write-error] + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      [write-error]     + CategoryInfo          : NotSpecified: (C:\Jenkins\work...ript.ps1 : bang:String) [], RemoteException
      [write-error]     + FullyQualifiedErrorId : NativeCommandError
      [write-error]  
      [write-error] At line:1 char:1
      [write-error] 
      [write-error] + & 'C:\Jenkins\workspace\owpos\pos\frp\00-build@tmp\durable-2fc4febd\p ...
      [write-error] 
      [write-error] + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      [write-error] 
      [write-error]     + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
      [write-error] 
      [write-error]     + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,powershellScript.ps1
      [write-error] 
      [write-error]  
      [write-error] 
      

      The plugin should behave like the documentation.

          [JENKINS-54036] Write-Error in powershell step behaves confusingly

          Torben Knerr added a comment -

          I was about to create the same issue, but gladly found akdor1154 already created this one

          For us this is happening on Jenkins LTS 2.150.1 with workflow-durable-task-step plugin v2.26

          Torben Knerr added a comment - I was about to create the same issue, but gladly found akdor1154 already created this one For us this is happening on Jenkins LTS 2.150.1 with workflow-durable-task-step plugin v2.26

          Torben Knerr added a comment -

          The documentation that is referred to can be found here:
          https://jenkins.io/blog/2017/07/26/powershell-pipeline/#what-causes-a-failing-exit-status

          (found it in a blog post only, the actual pipeline step reference does not mention this in detail)

          Torben Knerr added a comment - The documentation that is referred to can be found here: https://jenkins.io/blog/2017/07/26/powershell-pipeline/#what-causes-a-failing-exit-status (found it in a blog post only, the actual pipeline step reference does not mention this in detail)

          Torben Knerr added a comment -

          akdor1154 did you observe this is happening only with "PERFORMANCE_OPTIMIZED" durability? Asking, because we have that globally set to "PERFORMANCE_OPTIMIZED" too...

          Torben Knerr added a comment - akdor1154 did you observe this is happening only with "PERFORMANCE_OPTIMIZED" durability? Asking, because we have that globally set to "PERFORMANCE_OPTIMIZED" too...

          Running into this as well.

          I am passing in values to the Powershell step to execute, and in the event that something 'invalid' is passed, it's not properly failing the step.

          So for example:

          node{
            powershell(script: "Write-Output @['hello','world']")
          }
          

          Results in a successful step with the following output:

          [Pipeline] powershell
          powershell.exe : At D:\Jenkins-Windows\workspace\jenkinsfile@2@tmp\durable-a677ea80\powershellSc
          At D:\Jenkins-Windows\workspace\jenkinsfile@2@tmp\durable-a677ea80\powershellWrapper.ps1:3 char:1
          + & powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass -Comm ...
          + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
              + CategoryInfo          : NotSpecified: (At D:\Jenkins-W...80\powershellSc    :String) [], RemoteException
              + FullyQualifiedErrorId : NativeCommandError
           
          ript.ps1:2 char:16
          +   Write-Output @['hello','world']
          +                ~
          Unrecognized token in source text.
          
              + CategoryInfo          : ParserError: (:) [], ParseException
          
              + FullyQualifiedErrorId : UnrecognizedToken
          

          Jared Kauppila added a comment - Running into this as well. I am passing in values to the Powershell step to execute, and in the event that something 'invalid' is passed, it's not properly failing the step. So for example: node{ powershell(script: "Write-Output @[ 'hello' , 'world' ]" ) } Results in a successful step with the following output: [Pipeline] powershell powershell.exe : At D:\Jenkins-Windows\workspace\jenkinsfile@2@tmp\durable-a677ea80\powershellSc At D:\Jenkins-Windows\workspace\jenkinsfile@2@tmp\durable-a677ea80\powershellWrapper.ps1:3 char :1 + & powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass -Comm ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (At D:\Jenkins-W...80\powershellSc : String ) [], RemoteException + FullyQualifiedErrorId : NativeCommandError ript.ps1:2 char :16 + Write-Output @[ 'hello' , 'world' ] + ~ Unrecognized token in source text. + CategoryInfo : ParserError: (:) [], ParseException + FullyQualifiedErrorId : UnrecognizedToken

            Unassigned Unassigned
            akdor1154 Jarrad Whitaker
            Votes:
            3 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: