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

    Details

    • Similar Issues:

      Description

      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).

        Attachments

          Issue Links

            Activity

            davida2009 David Aldrich created issue -
            abayer Andrew Bayer made changes -
            Field Original Value New Value
            Component/s pipeline-stage-step-plugin [ 21709 ]
            Component/s pipeline-model-definition-plugin [ 21706 ]
            abayer Andrew Bayer made changes -
            Status Open [ 1 ] In Progress [ 3 ]
            abayer Andrew Bayer made changes -
            Status In Progress [ 3 ] In Review [ 10005 ]
            abayer Andrew Bayer made changes -
            Remote Link This issue links to "Stage Step plugin PR #10 (Web Link)" [ 16913 ]
            abayer Andrew Bayer made changes -
            Status In Review [ 10005 ] Resolved [ 5 ]
            Resolution Fixed [ 1 ]
            abayer Andrew Bayer made changes -
            Link This issue is duplicated by JENKINS-40443 [ JENKINS-40443 ]
            pyrocks Mor L made changes -
            Link This issue is related to JENKINS-48315 [ JENKINS-48315 ]
            pyrocks 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 ]

              People

              • Assignee:
                abayer Andrew Bayer
                Reporter:
                davida2009 David Aldrich
              • Votes:
                0 Vote for this issue
                Watchers:
                12 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: