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

Possibility to know the current stage in a Pipeline

      I search for a way to know the current stage into a Pipeline, checking the documentation there is not way to do that. as a workaround we could define a environment variable to manage it but it it is not too DRY, Is it possible to evaluate this feature?

      stage('Stage One'){
         env.STAGE = 'Stage One'
         ...
      }
      

      or

      env.STAGE = 'Stage One'
      stage(env.STAGE){
         ...
      }
      

          [JENKINS-40443] Possibility to know the current stage in a Pipeline

          what would be even cooler is something like:

          stage('Stage One'){
             echo currentStage.name // Stage One
             currentStage.result = 'UNSTABLE' // so we can mark the stage as skipped/unstable/failed if we want to without changing the global result
             ...
          }
          

          Daniel Geißler added a comment - what would be even cooler is something like: stage( 'Stage One' ){ echo currentStage.name // Stage One currentStage.result = 'UNSTABLE' // so we can mark the stage as skipped/unstable/failed if we want to without changing the global result ... }

          Sorin Sbarnea added a comment - - edited

          It seems that it was implemented as env.STAGE_NAME on JENKINS-44456

          Sorin Sbarnea added a comment - - edited It seems that it was implemented as  env.STAGE_NAME  on  JENKINS-44456

          Sorin Sbarnea added a comment -

          Does anyone knows how to get list of stages in groovy and check their status so I can determine which one failed?

          I want to do this kind of introspection at the end of the pipeline in order to build a nice error message. Due to the nature of the job is not possible to add try/catch blocks on 15-20 stages which are in fact stored in multiple files.

          Sorin Sbarnea added a comment - Does anyone knows how to get list of stages in groovy and check their status so I can determine which one failed? I want to do this kind of introspection at the end of the pipeline in order to build a nice error message. Due to the nature of the job is not possible to add try/catch blocks on 15-20 stages which are in fact stored in multiple files.

          Frank Escobar added a comment -

          It would be good if we can get the stageName and stageResult

          Frank Escobar added a comment - It would be good if we can get the stageName and stageResult

            ssbarnea Sorin Sbarnea
            ifernandezcalvo Ivan Fernandez Calvo
            Votes:
            13 Vote for this issue
            Watchers:
            10 Start watching this issue

              Created:
              Updated:
              Resolved: