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

The error step is not setting the currentBuild.result nor currentBuild.currentResult

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      When using error 'foo' in a scripted pipeline, it seems that the currentBuild.result or currentBuild.currentResult are not set accordingly. Here is a simple reproductible script:

      node {
        try {
          echo currentBuild.currentResult
          error 'foo'
        } finally {
          echo currentBuild.currentResult
        }
      }

      and the output is 

      [Pipeline] node
      Running on master in /tmp/jenkins-home/workspace/foo
      [Pipeline] {
      [Pipeline] echo
      SUCCESS
      [Pipeline] error
      [Pipeline] echo
      SUCCESS
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] End of Pipeline
      ERROR: foo
      Finished: FAILURE

      Is this because, in the finally block, the "exception" thrown by error happened but it not yet handled to quite the execution of the currentBuild?

        Attachments

          Activity

          Hide
          abayer Andrew Bayer added a comment -

          That sounds right. Needs more investigation.

          Show
          abayer Andrew Bayer added a comment - That sounds right. Needs more investigation.
          Hide
          abayer Andrew Bayer added a comment -

          So yeah, currentBuild.result (and therefore currentBuild.currentResult) isn't set until we get out of the finally. I think that's how it should be.

          Show
          abayer Andrew Bayer added a comment - So yeah, currentBuild.result (and therefore currentBuild.currentResult ) isn't set until we get out of the finally . I think that's how it should be.
          Hide
          alecharp Adrien Lecharpentier added a comment - - edited

          I agree, there is nothing wrong with this. Just that we cannot rely on the currentBuild.currentResult on the finally for notifications or other things.

           

          We can close this, I have my answer. Thanks!

          Show
          alecharp Adrien Lecharpentier added a comment - - edited I agree, there is nothing wrong with this. Just that we cannot rely on the currentBuild.currentResult on the finally for notifications or other things.   We can close this, I have my answer. Thanks!

            People

            • Assignee:
              abayer Andrew Bayer
              Reporter:
              alecharp Adrien Lecharpentier
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: