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

durable-task-plugin 1.23 powershell step does not return exit code other than 0 or 1

    Details

    • Type: Bug
    • Status: Resolved (View Workflow)
    • Priority: Minor
    • Resolution: Fixed
    • Component/s: durable-task-plugin
    • Labels:
      None
    • Environment:
      Jenkins ver. 2.121.2
      durable-task-plugin 1.23
    • Similar Issues:
    • Released As:
      durable-task 1.30

      Description

       

      After upgrading to durable-task-plugin 1.23, the powershell step does not return the correct non-zero exit code. In version 1.22 the code was correct.

      powershell 'exit 123'

      ERROR: script returned exit code 1

       

       

      def status = powershell(returnStatus:true, script:'exit 123')
      echo "$status" 

      [Pipeline] echo
      1

       

        Attachments

          Activity

          Hide
          descoffery Dustin Escoffery added a comment -

          I believe the bug was introduced in

          https://github.com/jenkinsci/durable-task-plugin/pull/71

          https://github.com/jenkinsci/durable-task-plugin/commit/e7f0dd5e7c7018b58dac08bfbc49b8037480a282

           

          Consider powershell script "test.ps1" with contents:

           

          exit 2
          

           

           

          Prior to the change, the old method correctly sets the error code to 2:

           

          & powershell -ExecutionPolicy ByPass -File test.ps1
          $LASTEXITCODE
          

          2

           

           

          After the change (durable-task 1.23 and above), the new method incorrectly sets the error code to 1:

           

          & powershell -ExecutionPolicy ByPass -Command "& .\test.ps1"
          $LASTEXITCODE
          

          1

           

           

          This example uses PSVersion 5.1.16299.967

          Show
          descoffery Dustin Escoffery added a comment - I believe the bug was introduced in https://github.com/jenkinsci/durable-task-plugin/pull/71 https://github.com/jenkinsci/durable-task-plugin/commit/e7f0dd5e7c7018b58dac08bfbc49b8037480a282   Consider powershell script "test.ps1" with contents:   exit 2     Prior to the change, the old method correctly sets the error code to 2:   & powershell -ExecutionPolicy ByPass -File test.ps1 $LASTEXITCODE 2     After the change (durable-task 1.23 and above), the new method incorrectly sets the error code to 1:   & powershell -ExecutionPolicy ByPass -Command "& .\test.ps1" $LASTEXITCODE 1     This example uses PSVersion 5.1.16299.967
          Hide
          gabloe Gabriel Loewen added a comment -

          The change to using -Command was to solve a different regression in Powershell versions < 5.  The fix here is to add an additional exit $LASTEXITCODE within the command block.  e.g.:

           

          & powershell -ExecutionPolicy ByPass -Command "& .\test.ps1; exit $LASTEXITCODE;"
          $LASTEXITCODE
          

          2

           

          I'll send a PR shortly with this fix.

          Show
          gabloe Gabriel Loewen added a comment - The change to using -Command was to solve a different regression in Powershell versions < 5.  The fix here is to add an additional exit $LASTEXITCODE within the command block.  e.g.:   & powershell -ExecutionPolicy ByPass -Command "& .\test.ps1; exit $LASTEXITCODE;" $LASTEXITCODE 2   I'll send a PR shortly with this fix.
          Show
          gabloe Gabriel Loewen added a comment - PR sent  https://github.com/jenkinsci/durable-task-plugin/pull/90
          Hide
          lystor Mykola Ulianytskyi added a comment -

          When the updated plugin will be released?

          Thank you

          Show
          lystor Mykola Ulianytskyi added a comment - When the updated plugin will be released? Thank you
          Hide
          dnusbaum Devin Nusbaum added a comment -

          A fix for this issue was just released in version 1.30 of Durable Task Plugin.

          Show
          dnusbaum Devin Nusbaum added a comment - A fix for this issue was just released in version 1.30 of Durable Task Plugin.

            People

            • Assignee:
              gabloe Gabriel Loewen
              Reporter:
              descoffery Dustin Escoffery
            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: