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

Step to set stage or parallel status

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Reopened (View Workflow)
    • Priority: Critical
    • Resolution: Unresolved
    • Component/s: blueocean-plugin, pipeline
    • Labels:
      None
    • Environment:
      Jenkins LTS v2.46.3
      Pipeline plugin v2.5
      Blue Ocean v1.1.4
    • Similar Issues:
    • Released As:
      Pipeline: Basic Steps 2.16

      Description

      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.

        Attachments

          Issue Links

            Activity

            Hide
            nofarblue Nofar Bluestein added a comment - - edited

            Thank you for the feedback!

            Saad Azam I cannot commit to an ETA at the moment, but I can tell you it's a high priority for us,. I will provide additional update soon. 

            Nancy Robertson in scripted pipelines the following should work: 

             `warnError { error() }` would have the same result, but I will consider adding 'unstable' step so it's more elegant and consistent with the 'error' step

             

            Show
            nofarblue Nofar Bluestein added a comment - - edited Thank you for the feedback! Saad Azam I cannot commit to an ETA at the moment, but I can tell you it's a high priority for us,. I will provide additional update soon.  Nancy Robertson in scripted pipelines the following should work:   `warnError { error() }` would have the same result, but I will consider adding 'unstable' step so it's more elegant and consistent with the 'error' step  
            Hide
            shanidar1 Shani Dar added a comment -

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

            Show
            shanidar1 Shani Dar added a comment - Nofar Bluestein  Thanks for the update! looking forward to use the stage status solution.  
            Hide
            dnusbaum Devin Nusbaum added a comment -

            Pipeline: Basic Steps Plugin version 2.16 added the new warnError and unstable steps and changes to catchError that Nofar Bluestein 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?

            Show
            dnusbaum Devin Nusbaum added a comment - Pipeline: Basic Steps Plugin version 2.16 added the new warnError and unstable steps and changes to catchError that Nofar Bluestein 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?
            Hide
            rrrrrrrr 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.

            Show
            rrrrrrrr 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.
            Hide
            saad_azam Saad Azam added a comment -

            Devin Nusbaum 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.

            Show
            saad_azam Saad Azam added a comment - Devin Nusbaum  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.

              People

              • Assignee:
                Unassigned
                Reporter:
                leedega Kevin Phillips
              • Votes:
                151 Vote for this issue
                Watchers:
                170 Start watching this issue

                Dates

                • Created:
                  Updated: