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

Allow dynamic stage names

    XMLWordPrintable

Details

    Description

      I would like the ability to have stage names be dynamic strings. This is useful, for instance, when defining stages within a matrix, so that the stage names can contain the values of the axes. (Part of the problem here is that Blue Ocean doesn't render matrixes well at all.) Right now attempting to do this yields an error because stage names can only be string literals, not Groovy strings (interpolation).

      Note that I am not looking for the steps within the stage to be dynamic.

      Example:

      matrix {
          axes {
              axis {
                  name 'PLATFORM'
                  values 'linux', 'mac', 'windows'
              }
          }
          stages {
              stage("Build ${PLATFORM}") {
                  // ...
              }
              stage("Test ${PLATFORM}") {
                  // ...
              }
              stage("Deploy ${PLATFORM}") {
                  // ...
              }
          }
      }
      

      Attachments

        Activity

          rittneje Jesse Rittner added a comment -

          pfuntner What you are seeing is declarative vs. scripted pipelines. Generally declarative pipelines have more constraints, but you can use a script block as an escape hatch to go from declarative to scripted. The stage block in a declarative pipeline and the stage function in a scripted pipeline are analogous to each other but are not entirely equivalent.

          rittneje Jesse Rittner added a comment - pfuntner What you are seeing is declarative vs. scripted pipelines. Generally declarative pipelines have more constraints, but you can use a script block as an escape hatch to go from declarative to scripted. The stage block in a declarative pipeline and the stage function in a scripted pipeline are analogous to each other but are not entirely equivalent.
          pfuntner John Pfuntner added a comment - - edited

          I'm dealing with a project with several Jenkins scripts - some of them appear to accept a variable in the stage.  I don't understand why but it seems that if the stage statement is inside a script block, you can specify a variable in the stage name:

          stages {
            stage('static name') {
              steps {
                script {
                  stage("dynamic name with ${ENV.name}") {
                    .
                    .
                    .
                  }
                }
              }
            }
          }
          
          pfuntner John Pfuntner added a comment - - edited I'm dealing with a project with several Jenkins scripts - some of them appear to accept a variable in the stage.  I don't understand why but it seems that if the stage statement is inside a script block, you can specify a variable in the stage name: stages { stage('static name') { steps { script { stage("dynamic name with ${ENV.name}") { . . . } } } } }
          nehamittal3010 Neha Mittal added a comment -

          Hi bitwiseman ,

          Are we getting  fix with this issue as we are blocked and cannot use this. Please let us know when is ETA planned.

          Regards,

          Neha. 

          nehamittal3010 Neha Mittal added a comment - Hi bitwiseman , Are we getting  fix with this issue as we are blocked and cannot use this. Please let us know when is ETA planned. Regards, Neha. 
          kohenchia Kohen Chia added a comment -

          Upvoted. Please add this feature. I'm begging you.

          kohenchia Kohen Chia added a comment - Upvoted. Please add this feature. I'm begging you.

          omkar143 I've fixed it
          Please give it another try now.

          aabouzaid Ahmed AbouZaid added a comment - omkar143 I've fixed it Please give it another try now.

          People

            bitwiseman Liam Newman
            rittneje Jesse Rittner
            Votes:
            51 Vote for this issue
            Watchers:
            48 Start watching this issue

            Dates

              Created:
              Updated: