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

Provide a way to access a stage name from within the stage and its contents

      Please provide a way to access the stage name from within the stage and its contents (like post).

      Background

      I have a multibranch declarative script. I am struggling with the limitation of one JenkinsFile per branch. I want to run various tasks (i.e. stages) on the branch (e.g. build several separate apps) and have a clear indication of which stage failed in the email notification subject sent on failure. I assume that stage processing will stop as soon as one stage fails. The post clause can then call the email-ext plugin and specify in Subject the stage that failed. Developers will then see quickly which task failed, rather than having to look through the console log (or email body).

          [JENKINS-44456] Provide a way to access a stage name from within the stage and its contents

          David Aldrich created issue -
          Andrew Bayer made changes -
          Component/s New: pipeline-stage-step-plugin [ 21709 ]
          Component/s Original: pipeline-model-definition-plugin [ 21706 ]
          Andrew Bayer made changes -
          Status Original: Open [ 1 ] New: In Progress [ 3 ]
          Andrew Bayer made changes -
          Status Original: In Progress [ 3 ] New: In Review [ 10005 ]
          Andrew Bayer made changes -
          Remote Link New: This issue links to "Stage Step plugin PR #10 (Web Link)" [ 16913 ]
          Andrew Bayer made changes -
          Resolution New: Fixed [ 1 ]
          Status Original: In Review [ 10005 ] New: Resolved [ 5 ]
          Andrew Bayer made changes -
          Link New: This issue is duplicated by JENKINS-40443 [ JENKINS-40443 ]
          Mor L made changes -
          Link New: This issue is related to JENKINS-48315 [ JENKINS-48315 ]
          Mor L made changes -
          Comment [ I have another issue...

          The environment variable does not seem to persist when the stage ends prematurely. here's an example:

           
          {code:java}
          node('windows') {
              try {
                  stage('MY STAGE') {
                      echo "before=" + env.STAGE_NAME
                      error('something bad happened')
                      echo "after=" + env.STAGE_NAME
                  }
              } catch (def e) {
                  echo "after failure="+env.STAGE_NAME
                  throw e
              }
          }{code}
          console output:
          {code:java}
          Started by user admin
          [Pipeline] node
          Running on SLAVE01 in F:\jenkins-remote\workspace\stagename
          [Pipeline] {
          [Pipeline] stage
          [Pipeline] { (MY STAGE)
          [Pipeline] echo
          before=MY STAGE
          [Pipeline] error
          [Pipeline] }
          [Pipeline] // stage
          [Pipeline] echo
          after failure=null
          [Pipeline] }
          [Pipeline] // node
          [Pipeline] End of Pipeline
          ERROR: something bad happened
          Finished: FAILURE
          {code}
          I will open a new issue for it ]

            abayer Andrew Bayer
            davida2009 David Aldrich
            Votes:
            0 Vote for this issue
            Watchers:
            14 Start watching this issue

              Created:
              Updated:
              Resolved: