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

An additional final stage is required to make previous stage fail when it should

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      If I have a single stage pipeline that calls an sh script that deliberately fails, and I use try .. catch around the script, then the stage is marked as "green/success" in the pipeline, but it should be marked as "pink/failed."
      However, if I then add a final additional stage, the original first stage (previous stage) will then correctly be marked as "pink/failed."

      Here is some simple Jenkinsfile code that demonstrates the problem.

      
      
      def machine1 = 'mymachine'
      
      node (machine1) {
      
          currentBuild.result='SUCCESS'
      
          stage "Stage One"
      
          try {
              sh "banana"
          }
          catch (err) {
              echo "Stage One Failed: ${err}"
              currentBuild.result='FAILURE'
          }
          
          // 
          // We need this final stage to mark the end of the preceding stage,
          // so that the preceding stage's code will fail if its sh script fails
          // 
         // stage "End"
          
          echo "We've reached the end of the '${env.JOB_NAME}' pipeline. The build has finished."
      
      }
      
      

      You will see that the first (and only) stage is marked as green passed.
      If you uncomment the penultimate line stage "End" then you will find the first stage to be marked as pink failed, which is correct.

      Thanks

        Attachments

          Issue Links

            Activity

            Hide
            svanoort Sam Van Oort added a comment -

            I believe this is now resolved by work on JENKINS-33700

            Show
            svanoort Sam Van Oort added a comment - I believe this is now resolved by work on JENKINS-33700
            Hide
            svanoort Sam Van Oort added a comment -

            Will Berriss, I should clarify: the specific case you give will be resolved by the fix/enhancement PR combo I am tying to JENKINS-33700, because the single stage does not reflect overall build status and that will ensure the final stage gets its status correctly.

            That said, in the more general case this and JENKINS-34212 are mutually exclusive: either we show a stage as successful when an error is thrown but caught, or we look for any errors (caught or not) and mark the stage accordingly (the final stage gets the overall build status). There's no way in a pipeline to track when the build result was modified by the script using the currentBuild.result variable. The handling in JENKINS-34212 is more correct (caught errors can be ignored), so that will be the implemented behavior.

            Basically: if you're using caught errors to flag specific stages, that's going away because it depends on a bug. There are planned enhancements to allow richer information to be supplied for a stage (JENKINS-26522) which will give you the ability to decorate stages properly to supply additional info.

            Show
            svanoort Sam Van Oort added a comment - Will Berriss , I should clarify: the specific case you give will be resolved by the fix/enhancement PR combo I am tying to JENKINS-33700 , because the single stage does not reflect overall build status and that will ensure the final stage gets its status correctly. That said, in the more general case this and JENKINS-34212 are mutually exclusive: either we show a stage as successful when an error is thrown but caught, or we look for any errors (caught or not) and mark the stage accordingly (the final stage gets the overall build status). There's no way in a pipeline to track when the build result was modified by the script using the currentBuild.result variable. The handling in JENKINS-34212 is more correct (caught errors can be ignored), so that will be the implemented behavior. Basically: if you're using caught errors to flag specific stages, that's going away because it depends on a bug. There are planned enhancements to allow richer information to be supplied for a stage ( JENKINS-26522 ) which will give you the ability to decorate stages properly to supply additional info.
            Hide
            svanoort Sam Van Oort added a comment -

            Tested, reviewed, and merged: going live with the next release.

            Show
            svanoort Sam Van Oort added a comment - Tested, reviewed, and merged: going live with the next release.
            Hide
            svanoort Sam Van Oort added a comment -

            Released fix with v 1.6

            Show
            svanoort Sam Van Oort added a comment - Released fix with v 1.6

              People

              • Assignee:
                svanoort Sam Van Oort
                Reporter:
                will177 Will Berriss
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: