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

PowerShell - Errors do not cause build to fail?

    XMLWordPrintable

Details

    • Bug
    • Status: Open (View Workflow)
    • Minor
    • Resolution: Unresolved
    • powershell-plugin
    • None
    • Jenkins 2.249.2, Windows 10 v2004, PowerShell 7.0.3

    Description

      See related posts:

      https://www.reddit.com/r/jenkinsci/comments/jb6591/powershell_pipeline_example_doesnt_return/

      https://www.jenkins.io/blog/2017/07/26/powershell-pipeline/

      https://issues.jenkins-ci.org/browse/JENKINS-63944

      Basically, the example from the Jenkins blog post on PowerShell does not display the expected output (build failure) when writing an error, despite the output in the blog post clearly showing that the build failed. This issue is present with both PowerShell 5.1 and PowerShell 7 on Windows, I did not test other PowerShell versions or operating systems.

      Attachments

        Activity

          markewaite Mark Waite added a comment - - edited

          jmcclain as far as I can tell from my test job, Jenkins 2.263.2 is correctly showing the failure of the example:

          node {
              powershell '''
                  throw 'Error! Problem Exists Between Keyboard And Chair'
                  exit 0  # Unreachable code
              '''
          }
          

          Can you check again?

          markewaite Mark Waite added a comment - - edited jmcclain as far as I can tell from my test job, Jenkins 2.263.2 is correctly showing the failure of the example: node { powershell ''' throw 'Error! Problem Exists Between Keyboard And Chair' exit 0 # Unreachable code ''' } Can you check again?
          jmcclain Jeffrey McClain added a comment - - edited

          Just updated Jenkins to 2.263.2 and also updated all the plugins, same issue.
          The test code in your comment doesn't seem to match this issue precisely though, to elaborate:

          From https://www.jenkins.io/blog/2017/07/26/powershell-pipeline/
          Section title: "Write to all available streams and return the standard output"

          node {
              def stdout = powershell(returnStdout: true, script: '''
                  # Enable streams 3-6
                  $WarningPreference = 'Continue'
                  $VerbosePreference = 'Continue'
                  $DebugPreference = 'Continue'
                  $InformationPreference = 'Continue'
          
                  Write-Output 'Hello, World!'
                  Write-Error 'Something terrible has happened!'
                  Write-Warning 'Warning! There is nothing wrong with your television set'
                  Write-Verbose 'Do not attempt to adjust the picture'
                  Write-Debug 'We will control the horizontal.  We will control the vertical'
                  Write-Information 'We can change the focus to a soft blur or sharpen it to crystal clarity.'
              ''')
              println stdout
          }
          

          The article states that running this code should result in the console output:

          ERROR: script returned exit code 1
          Finished: FAILURE
          

          However, when I copy / paste this code verbatim into my pipeline script within Jenkins on Windows 10 (https://i.imgur.com/8yYk7gE.png) and run it, I get (https://i.imgur.com/gsoCxq8.png):

          Finished: SUCCESS
          

          Could you please try simply copying / pasting the exact example code into your Jenkins instance and seeing if the pipeline shows a success or failure at the end? The point I'm trying to make is that the Jenkins article states this exact code should result in a failure, but in reality the code returns a success. I am not sure if the article is simply incorrect, if the Jenkins behaviour has changed since the article was written, etc.

          jmcclain Jeffrey McClain added a comment - - edited Just updated Jenkins to 2.263.2 and also updated all the plugins, same issue. The test code in your comment doesn't seem to match this issue precisely though, to elaborate: From https://www.jenkins.io/blog/2017/07/26/powershell-pipeline/ Section title: "Write to all available streams and return the standard output" node { def stdout = powershell(returnStdout: true , script: ''' # Enable streams 3-6 $WarningPreference = 'Continue' $VerbosePreference = 'Continue' $DebugPreference = 'Continue' $InformationPreference = 'Continue' Write-Output 'Hello, World!' Write-Error 'Something terrible has happened!' Write-Warning 'Warning! There is nothing wrong with your television set' Write-Verbose 'Do not attempt to adjust the picture' Write-Debug 'We will control the horizontal. We will control the vertical' Write-Information 'We can change the focus to a soft blur or sharpen it to crystal clarity.' ''') println stdout } The article states that running this code should result in the console output: ERROR: script returned exit code 1 Finished: FAILURE However, when I copy / paste this code verbatim into my pipeline script within Jenkins on Windows 10 ( https://i.imgur.com/8yYk7gE.png ) and run it, I get ( https://i.imgur.com/gsoCxq8.png): Finished: SUCCESS Could you please try simply copying / pasting the exact example code into your Jenkins instance and seeing if the pipeline shows a success or failure at the end? The point I'm trying to make is that the Jenkins article states this exact code should result in a failure, but in reality the code returns a success. I am not sure if the article is simply incorrect, if the Jenkins behaviour has changed since the article was written, etc.

          People

            Unassigned Unassigned
            jmcclain Jeffrey McClain
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: