• Icon: Improvement Improvement
    • Resolution: Fixed
    • Icon: Critical Critical
    • blueocean-plugin, pipeline
    • None
    • Jenkins LTS v2.46.3
      Pipeline plugin v2.5
      Blue Ocean v1.1.4
    • Pipeline: Basic Steps 2.16

      Problem
      There is no way to catch a failing block, mark it as "failed" with a user defined description and continue execution of the Pipeline.

      In the example below, the Optional Tests stage would always be successful.

      stage ('Optional Tests') {
              try {
                  echo "Running optional tests..."
                  sh 'exit -1'
              } catch (Exception err) {
                  echo 'Optional tests failed... don't propagate failure'
              }
      }
      

      Solution
      Introduce new steps that can set the state of the stage to UNSTABLE, FAILED, SUCCESS, ABORTED. The message specified would be visible on the UI in Blue Ocean.

      Example

      stage ('Optional Tests') {
              try {
                  echo "Running optional tests..."
                  sh 'exit -1'
              } catch (Exception err) {
                  unstable 'Optional tests failed... don't propagate failure'
              }
      }
      

      Notes

      • There is precedence here with the error signal step.
      • To ensure consistency the FAILED state should always fail the pipeline.
      • The UNSTABLE state is used by tests to mark a stage as problematic but allows execution of the Pipeline to continue.
      • Unstable should be expanded to handle the case where the intent of the Pipeline author is to record that there was a problem with the execution of the stage but execution is allowed to continue.

      Original Request
      I recently discovered that pipeline stages that are run in parallel which report different results from one another are not currently being displayed correctly in the Blue Ocean UI. Here is a short snippet of code that reproduces the problem case I found:

      node {
          parallel testA: {
              stage ("Required Tests") {
                  echo "Running required tests..."
              }
          }, testB: {
              try {
                  stage ("Optional Tests") {
                      echo "Running optional tests..."
                      sh 'exit -1'
                  }
              } catch (Exception err) {
                  echo "Optional tests failed... don't propagate failure"
              }
          }
          
          stage ("Deploy") {
              echo "Deploying..."
          }
      }
      

      Here I expect that 2 dummy test suites will be executed, one containing important tests that must all pass, and another containing less important tests that may be allowed to fail. Following these 2 parallel test stages is a final deploy stage that would be run afterwards so long as the "important" tests complete successfully.

      In this example I'd expect that the node in the pipeline graph for the 'testB' stage would show up red while the other 2 nodes would show up green. Currently this does not happen - all 3 stages show up as green. I've attached a sample screenshot to illustrate the results.

      It is also worth mentioning that the statuses of these stages does appear to be represented correctly in the old 'stage view' from the default Jenkins UI. I've attached a screenshot illustrating this as well.

          [JENKINS-45579] Step to set stage or parallel status

          Shani Dar added a comment -

          nofarblue Thanks for the update! looking forward to use the stage status solution.  

          Shani Dar added a comment - nofarblue  Thanks for the update! looking forward to use the stage status solution.  

          Devin Nusbaum added a comment -

          Pipeline: Basic Steps Plugin version 2.16 added the new warnError and unstable steps and changes to catchError that nofarblue mentioned, see the 2.16 release notes for details on the specifics. See this comment on JENKINS-39203 for additional information on related issues. You need to update to Pipeline: Graph Analysis 1.10 for these steps to be visualized correctly by Blue Ocean.

          Should we close this issue and open more specific issues related to the request for a step to set the build result to FAILURE but continue execution and a step to set the build result to ABORTED and abort the build, or handle them as part of this ticket?

          Devin Nusbaum added a comment - Pipeline: Basic Steps Plugin version 2.16 added the new warnError and unstable steps and changes to catchError that nofarblue mentioned, see the 2.16 release notes for details on the specifics. See this comment on JENKINS-39203 for additional information on related issues. You need to update to Pipeline: Graph Analysis 1.10 for these steps to be visualized correctly by Blue Ocean. Should we close this issue and open more specific issues related to the request for a step to set the build result to FAILURE but continue execution and a step to set the build result to ABORTED and abort the build, or handle them as part of this ticket?

          RG added a comment -

          Hi. Would you mind adding an example in https://github.com/jenkinsci/pipeline-examples ? I'm not exactly an expert and coming up with the right syntax  assembling bit of code & release note is quite hard.

          RG added a comment - Hi. Would you mind adding an example in https://github.com/jenkinsci/pipeline-examples ? I'm not exactly an expert and coming up with the right syntax  assembling bit of code & release note is quite hard.

          Saad Azam added a comment -

          dnusbaum I have tried the latest update with newly added 'unstable' step as well as updated 'catchError'. I am now able to setup and visualize individual stage status independently. Many thanks.

          Saad Azam added a comment - dnusbaum  I have tried the latest update with newly added 'unstable' step as well as updated 'catchError'. I am now able to setup and visualize individual stage status independently. Many thanks.

          Devin Nusbaum added a comment -

          rrrrrrrr You can use the "Pipeline Syntax" link in the sidebar of a Pipeline job in Jenkins to get a visual interface that will show you the options provided by catchError, warnError, and unstable and will allow you to generate the actual syntax that would go in a Pipeline given the options you specify.

          I will look into adding something to the examples repo.

          Devin Nusbaum added a comment - rrrrrrrr You can use the "Pipeline Syntax" link in the sidebar of a Pipeline job in Jenkins to get a visual interface that will show you the options provided by catchError , warnError , and unstable and will allow you to generate the actual syntax that would go in a Pipeline given the options you specify. I will look into adding something to the examples repo.

          Brian J Murrell added a comment - - edited

          I used the Pipeline Syntax snippet generator to generate me a catchError step and it produced:

          catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
           // some block
          }
          

          which then chokes Jenkins with:

          WorkflowScript: 147: Expecting "class hudson.model.Result" for parameter "buildResult" but got "SUCCESS" of type class java.lang.String instead @ line 147, column 49.
                   catchError(buildResult: 'SUCCESS',
                                           ^
          

          Removing the single quotes surrounding the SUCCESS and FAILURE values seems to at least keep the linter happy and the pipeline at least runs. Still waiting to see if these new values have the desired effect though.

          Brian J Murrell added a comment - - edited I used the Pipeline Syntax snippet generator to generate me a catchError step and it produced: catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') { // some block } which then chokes Jenkins with: WorkflowScript: 147: Expecting "class hudson.model.Result" for parameter "buildResult" but got "SUCCESS" of type class java.lang.String instead @ line 147, column 49. catchError(buildResult: 'SUCCESS', ^ Removing the single quotes surrounding the SUCCESS and FAILURE values seems to at least keep the linter happy and the pipeline at least runs. Still waiting to see if these new values have the desired effect though.

          Devin Nusbaum added a comment -

          brianjmurrell Yes, turns out that Declarative doesn't like the parameter types for `catchError`. See JENKINS-57537 for more information, I am working on a fix that should be ready soon.

          Devin Nusbaum added a comment - brianjmurrell Yes, turns out that Declarative doesn't like the parameter types for `catchError`. See JENKINS-57537 for more information, I am working on a fix that should be ready soon.

          dnusbaum Oh, this is a pity.    catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') was going to solve exactly the problem I newly have on hand today, which is how to let a step fail, mark it's stage as failed but not fail the overall job.

          I'm really loathed to make the step and stage look like it succeeded (because it will mask failures that need investigating) just so that the rest of the stages get run and overall job passes.

          Brian J Murrell added a comment - dnusbaum Oh, this is a pity.     catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE')  was going to solve exactly the problem I newly have on hand today, which is how to let a step fail, mark it's stage as failed but not fail the overall job. I'm really loathed to make the step and stage look like it succeeded (because it will mask failures that need investigating) just so that the rest of the stages get run and overall job passes.

          dnusbaum New issue filed about catchError(), and the post processing block, FWIW.

          Brian J Murrell added a comment - dnusbaum New issue filed about catchError() , and the post processing block, FWIW.

          Devin Nusbaum added a comment -

          The original example in the description of this ticket was fixed as part of JENKINS-39203 with the new warnError and unstable steps and changes to the catchError step, so I am going to close this issue See https://jenkins.io/blog/2019/07/05/jenkins-pipeline-stage-result-visualization-improvements/ and this earlier comment for details. if you have a request for a step that is related to the general title of the ticket but is not covered by the changes I mentioned, please file a new ticket along the lines of JENKINS-27092.

          Devin Nusbaum added a comment - The original example in the description of this ticket was fixed as part of JENKINS-39203 with the new warnError  and unstable steps and changes to the catchError step, so I am going to close this issue See https://jenkins.io/blog/2019/07/05/jenkins-pipeline-stage-result-visualization-improvements/  and this earlier comment for details. if you have a request for a step that is related to the general title of the ticket but is not covered by the changes I mentioned, please file a new ticket along the lines of JENKINS-27092 .

            dnusbaum Devin Nusbaum
            leedega Kevin Phillips
            Votes:
            154 Vote for this issue
            Watchers:
            173 Start watching this issue

              Created:
              Updated:
              Resolved: