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

Powershell Step Always Returns Success

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      When I run the following pipeline on a test jenkins instance running on my PC, it always returns successful:

      pipeline
      pipeline {
          agent {label 'master'}
          stages {
              stage('Build') {
                  steps {
                      powershell '''\
                          $LastExitCode = 2
                          Write-Error "Error"
                          throw "Except"
                          exit 1
                          '''
                  }
              }
         }
      }
      

      Here is the console output:

      "Console output"
      Started by user francis
      [Pipeline] node
      Running on Jenkins in C:\Program Files (x86)\Jenkins\workspace\test-pipeline
      [Pipeline] {
      [Pipeline] stage
      [Pipeline] { (Build)
      [Pipeline] powershell
      [test-pipeline] Running PowerShell script
      C:\Program Files (x86)\Jenkins\workspace\test-pipeline@tmp\durable-de77ada9\powershellScript.ps1 : Error
      At C:\Program Files (x86)\Jenkins\workspace\test-pipeline@tmp\durable-de77ada9\powershellMain.ps1:2 char:1
      + & 'C:\Program Files (x86)\Jenkins\workspace\test-pipeline@tmp\durable ...
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
          + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,powershellScript.ps1
       
      C:\Program Files (x86)\Jenkins\workspace\test-pipeline@tmp\durable-de77ada9\powershellMain.ps1 : Except
      At C:\Program Files (x86)\Jenkins\workspace\test-pipeline@tmp\durable-de77ada9\powershellWrapper.ps1:1 char:1
      + & "C:\Program Files (x86)\Jenkins\workspace\test-pipeline@tmp\durable ...
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
          + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,powershellMain.ps1
       
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] End of Pipeline
      Finished: SUCCESS
      

      This blog post states that any of these actions in powershell should trigger a failed build (throw an exception, return exit code != 0, write to error stream, set lastexitcode !=0). In fact, none of them are triggering it, I have tried each individually.

      I tried this on our production Jenkins machine, and it did trigger a failed build (expected behavior). This machine is running:

      Jenkins v2.60.2
      Declarative Pipeline v1.1.9
      Nodes and Processes v2.13
      Durable Task v1.14

      Machine is a Linux Slave, and the pipeline got executed on a Windows 7 slave. Therefore, I don't know whether this bug is caused by the newer version on my test setup, by the fact that it gets executed on the master, or by the OS differences.

      I am marking this as major because a pipeline falsely marked as Successful in production could be a major problem.

        Attachments

          Activity

          Hide
          gabloe Gabriel Loewen added a comment -

          I cannot reproduce this.

          Pipeline:

           

          pipeline {
              agent any
              stages {
                  stage('Build') {
                      steps {
                          powershell '''
                              $LastExitCode = 2
                              Write-Error "Error"
                              throw "Except"
                              exit 1
                              '''
                      }
                  }
             }
          }

           

          Result:

           

          [Pipeline] {
          [Pipeline] stage
          [Pipeline] { (Build)
          [Pipeline] powershell
          [Test-PowerShellFailure] Running PowerShell script
          C:\Program Files (x86)\Jenkins\workspace\Test-PowerShellFailure@tmp\durable-8394ad55\powershellScript.ps1 : Error
          At C:\Program Files (x86)\Jenkins\workspace\Test-PowerShellFailure@tmp\durable-8394ad55\powershellMain.ps1:2 char:1
          + & 'C:\Program Files (x86)\Jenkins\workspace\Test-PowerShellFailure@tm ...
          + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
              + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
              + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,powershellScript.ps1
           
          C:\Program Files (x86)\Jenkins\workspace\Test-PowerShellFailure@tmp\durable-8394ad55\powershellMain.ps1 : Except
          At C:\Program Files (x86)\Jenkins\workspace\Test-PowerShellFailure@tmp\durable-8394ad55\powershellWrapper.ps1:1 char:1
          + & "C:\Program Files (x86)\Jenkins\workspace\Test-PowerShellFailure@tm ...
          + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
              + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
              + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,powershellMain.ps1
           
          [Pipeline] }
          [Pipeline] // stage
          [Pipeline] }
          [Pipeline] // node
          [Pipeline] End of Pipeline
          ERROR: script returned exit code 1
          Finished: FAILURE
          

           

           

          Show
          gabloe Gabriel Loewen added a comment - I cannot reproduce this. Pipeline:   pipeline {     agent any     stages {         stage( 'Build' ) {             steps {                 powershell '''                     $LastExitCode = 2                     Write-Error "Error"                     throw "Except"                     exit 1                     '''             }         }    } }   Result:   [Pipeline] { [Pipeline] stage [Pipeline] { (Build) [Pipeline] powershell [Test-PowerShellFailure] Running PowerShell script C:\Program Files (x86)\Jenkins\workspace\Test-PowerShellFailure@tmp\durable-8394ad55\powershellScript.ps1 : Error At C:\Program Files (x86)\Jenkins\workspace\Test-PowerShellFailure@tmp\durable-8394ad55\powershellMain.ps1:2 char :1 + & 'C:\Program Files (x86)\Jenkins\workspace\Test-PowerShellFailure@tm ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,powershellScript.ps1 C:\Program Files (x86)\Jenkins\workspace\Test-PowerShellFailure@tmp\durable-8394ad55\powershellMain.ps1 : Except At C:\Program Files (x86)\Jenkins\workspace\Test-PowerShellFailure@tmp\durable-8394ad55\powershellWrapper.ps1:1 char :1 + & "C:\Program Files (x86)\Jenkins\workspace\Test-PowerShellFailure@tm ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,powershellMain.ps1 [Pipeline] } [Pipeline] // stage [Pipeline] } [Pipeline] // node [Pipeline] End of Pipeline ERROR: script returned exit code 1 Finished: FAILURE    
          Hide
          ftherien Francis Therien added a comment -

          Hi Gabriel,

          Is the job running on master? What windows/powershell version? What version of durable task/jenkins?

          On my end, I just upgraded my local test instance to Jenkins 2.90 and Durable Task 1.16 this morning. Funnily enough, all powershell tasks now fully refuse to run (hang indefinitely).

          Show
          ftherien Francis Therien added a comment - Hi Gabriel, Is the job running on master? What windows/powershell version? What version of durable task/jenkins? On my end, I just upgraded my local test instance to Jenkins 2.90 and Durable Task 1.16 this morning. Funnily enough, all powershell tasks now fully refuse to run (hang indefinitely).
          Hide
          gabloe Gabriel Loewen added a comment -

          This is running on:

          Powershell 5.1.16299.15

          Durable task 1.15

          Jenkins 2.73.3

          Not running on master though.

           

          The powershell step hanging issue is one that was not caught by tests and did not reproduce in my testing before durable task 1.6 was released. However, I understand the issue and have sent a PR with a fix: https://github.com/jenkinsci/durable-task-plugin/pull/51

          Show
          gabloe Gabriel Loewen added a comment - This is running on: Powershell 5.1.16299.15 Durable task 1.15 Jenkins 2.73.3 Not running on master though.   The powershell step hanging issue is one that was not caught by tests and did not reproduce in my testing before durable task 1.6 was released. However, I understand the issue and have sent a PR with a fix:  https://github.com/jenkinsci/durable-task-plugin/pull/51
          Hide
          scm_issue_link SCM/JIRA link daemon added a comment -

          Code changed in jenkins
          User: Sam Van Oort
          Path:
          src/main/java/org/jenkinsci/plugins/durabletask/PowershellScript.java
          src/main/resources/org/jenkinsci/plugins/durabletask/powershellHelper.ps1
          src/test/java/org/jenkinsci/plugins/durabletask/PowershellScriptTest.java
          http://jenkins-ci.org/commit/durable-task-plugin/4a06f3cc8eb9053c0bf5597a06b69163c005c3b0
          Log:
          Merge pull request #51 from gabloe/master

          Fixed JENKINS-46876, JENKINS-46508, JENKINS-46496, JENKINS-48057, and JENKINS-47797

          Compare: https://github.com/jenkinsci/durable-task-plugin/compare/7c12b3a72cb4...4a06f3cc8eb9

          Show
          scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Sam Van Oort Path: src/main/java/org/jenkinsci/plugins/durabletask/PowershellScript.java src/main/resources/org/jenkinsci/plugins/durabletask/powershellHelper.ps1 src/test/java/org/jenkinsci/plugins/durabletask/PowershellScriptTest.java http://jenkins-ci.org/commit/durable-task-plugin/4a06f3cc8eb9053c0bf5597a06b69163c005c3b0 Log: Merge pull request #51 from gabloe/master Fixed JENKINS-46876 , JENKINS-46508 , JENKINS-46496 , JENKINS-48057 , and JENKINS-47797 Compare: https://github.com/jenkinsci/durable-task-plugin/compare/7c12b3a72cb4...4a06f3cc8eb9
          Hide
          svanoort Sam Van Oort added a comment -

          Released with 1.18

          Show
          svanoort Sam Van Oort added a comment - Released with 1.18

            People

            • Assignee:
              gabloe Gabriel Loewen
              Reporter:
              ftherien Francis Therien
            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: