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

Powershell Step Always Returns Success

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • None
    • Jenkins v2.87
      Nodes and Processes v2.17
      Durable Task v1.15
      Declarative Pipeline v1.2.2
      Pipeline v2.5

      Jenkins master is running on a windows 10 machine

      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.

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

              Created:
              Updated:
              Resolved: