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

Powershell Step Always Returns Success



    • Similar Issues:


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

      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.



          ftherien Francis Therien created issue -
          abayer Andrew Bayer made changes -
          Field Original Value New Value
          Component/s workflow-durable-task-step-plugin [ 21715 ]
          Component/s pipeline [ 21692 ]
          gabloe Gabriel Loewen made changes -
          Assignee Gabriel Loewen [ gabloe ]
          gabloe Gabriel Loewen made changes -
          Status Open [ 1 ] In Progress [ 3 ]
          jglick Jesse Glick made changes -
          Status In Progress [ 3 ] In Review [ 10005 ]
          svanoort Sam Van Oort made changes -
          Resolution Fixed [ 1 ]
          Status In Review [ 10005 ] Closed [ 6 ]


            gabloe Gabriel Loewen
            ftherien Francis Therien
            0 Vote for this issue
            5 Start watching this issue