• 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 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.
          Jesse Glick made changes -
          Link New: This issue relates to JENKINS-31931 [ JENKINS-31931 ]
          Jesse Glick made changes -
          Component/s New: core [ 15593 ]
          Component/s Original: workflow-basic-steps-plugin [ 21712 ]
          Jesse Glick made changes -
          Assignee Original: Andrew Bayer [ abayer ] New: Jesse Glick [ jglick ]
          Jesse Glick made changes -
          Status Original: Open [ 1 ] New: In Progress [ 3 ]

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

              Created:
              Updated:
              Resolved: