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

Try/catch around a stage will show the stage as failing (correct) but following stages also show as red

XMLWordPrintable

      If you use try/catch around a stage, the stage can fail and will be shown as a failure and the pipeline will still proceed (correct). Unfortunately the following stages aren't displayed correctly for purposes of pass/fail state.

      Sample job that will reproduce this:

      try {
          stage('failFirst') {
              error('Fail')    
          }
      } catch (Exception ex) {
          
      }
      
      try {
          stage('failSecond') {
              error('Fail')
          }
      } catch (Exception ex) {
          
      }
      
      stage('passOrFail') {
          echo 'run'
      }
      

      ALTERNATELY If the build fails overall:

      try {
          stage('failFirst') {
              error('Fail')    
          }
      } catch (Exception ex) {
          
      }
      
      try {
          stage('failSecond') {
              error('Fail')
          }
      } catch (Exception ex) {
          
      }
      
      stage('passOrFail') {
          echo 'run'
      }
      currentBuild.result = 'FAILURE'
      

      Screenshot:

      Note that in both cases, the last stage should probably be a passing stage.

      This is probably fixable by UI template and/or CSS.

            svanoort Sam Van Oort
            svanoort Sam Van Oort
            Votes:
            4 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: