• Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • core
    • Jenkins 2.78
      Pipeline job

      If I surround a General build step (as described in the snippet generator)  in a try-catch block, within a scripted Jenkins file, the error is not caught.

      for example I expected the following code block to mark the build as unstable. But an error is thrown at the archiveArtifacts step.

      node(){
          stage('Failing Archive'){
              try{
                  archiveArtifacts 'non existent path'
              }
              catch (err)
              {
                  echo 'Archive failed!'
                  currentBuild.result = 'UNSTABLE'
              }
          }
      }
      

       
      EDIT (abayer): More generally - CoreStep executions of a SimpleBuildStep (such as archiveArtifacts, which is actually calling the ArtifactArchiver publisher from core), only throw an exception if the SimpleBuildStep itself throws an exception. And as a general rule, failure-but-not-error cases (like the non-existent path case here) of a SimpleBuildStep don't throw an exception, since the FreeStyleBuild they were initially used in would proceed anyway (especially in the case of publishers/recorders, which are the most common SimpleBuildStep implementations), after having set the build status.

          [JENKINS-47142] archiveArtifacts step failure is not displayed

          L Wright created issue -

          Daniel Beck added a comment -

          This is log output, not an exception. What is this issue about?

          Daniel Beck added a comment - This is log output, not an exception. What is this issue about?

          L Wright added a comment -

          I would expect the try-catch block to catch the archiveArtifact error, and follow through on the catch clause. As a result the build status should unstable not failure.

          L Wright added a comment - I would expect the try-catch block to catch the archiveArtifact error, and follow through on the catch clause. As a result the build status should unstable not failure.
          Daniel Beck made changes -
          Component/s Original: core [ 15593 ]
          Andrew Bayer made changes -
          Link New: This issue is duplicated by JENKINS-44407 [ JENKINS-44407 ]
          Andrew Bayer made changes -
          Component/s New: workflow-basic-steps-plugin [ 21712 ]
          Component/s Original: pipeline [ 21692 ]
          Andrew Bayer made changes -
          Summary Original: Try-catch doesn't catch errors from general build steps New: CoreStep execution of SimpleBuildSteps doesn't actually fail in Pipeline
          Andrew Bayer made changes -
          Assignee New: Andrew Bayer [ abayer ]
          Andrew Bayer made changes -
          Description Original: If I surround a General build step (as described in the snippet generator)  in a try-catch block, within a scripted Jenkins file, the error is not caught.

          for example I expected the following code block to mark the build as unstable. But an error is thrown at the archiveArtifacts step.
          {code:java}
          node(){
              stage('Failing Archive'){
                  try{
                      archiveArtifacts 'non existent path'
                  }
                  catch (err)
                  {
                      echo 'Archive failed!'
                      currentBuild.result = 'UNSTABLE'
                  }
              }
          }
          {code}
           
          New: If I surround a General build step (as described in the snippet generator)  in a try-catch block, within a scripted Jenkins file, the error is not caught.

          for example I expected the following code block to mark the build as unstable. But an error is thrown at the archiveArtifacts step.
          {code:java}
          node(){
              stage('Failing Archive'){
                  try{
                      archiveArtifacts 'non existent path'
                  }
                  catch (err)
                  {
                      echo 'Archive failed!'
                      currentBuild.result = 'UNSTABLE'
                  }
              }
          }
          {code}
           
          EDIT (abayer): More generally - {{CoreStep}} executions of a {{SimpleBuildStep}} (such as {{archiveArtifacts}}, which is actually calling the {{ArtifactArchiver}} publisher from core), only throw an exception if the {{SimpleBuildStep}} itself throws an exception. And as a general rule, failure-but-not-error cases (like the non-existent path case here) of a {{SimpleBuildStep}} don't throw an exception, since the {{FreeStyleBuild}} they were initially used in would proceed anyway (especially in the case of publishers/recorders, which are the most common {{SimpleBuildStep}} implementations), after having set the build status.

          Andrew Bayer added a comment -

          I've refined the description a bit (as well as the summary) - JENKINS-44407 is another symptom of the same underlying problem: CoreStep only throws an exception (and marks its FlowNode as failed) if the SimpleBuildStep throws an exception, but as a general rule, a SimpleBuildStep won't throw an exception unless something goes very wrong.

          I'm not sure there's much we can do about this, but I'll leave it open and assigned to me for future pondering.

          Andrew Bayer added a comment - I've refined the description a bit (as well as the summary) - JENKINS-44407 is another symptom of the same underlying problem: CoreStep only throws an exception (and marks its FlowNode as failed) if the SimpleBuildStep throws an exception, but as a general rule, a SimpleBuildStep won't throw an exception unless something goes very wrong. I'm not sure there's much we can do about this, but I'll leave it open and assigned to me for future pondering.

            jglick Jesse Glick
            wright L Wright
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: