Useful to give a label to one or more steps that are otherwise opaque in the log.

      stage('Deploying') {
          sh './deploy.sh --some-long-arguments'
      }
      

      FlowGraphTable should hide the body of the label step by default.

      Alternatives considered:

      sh script: './deploy.sh', label: 'Deploying'
      

      which does not scale well as a design (labeling should be orthogonal to step definitions); or implicit label creation when Groovy label expressions are encountered:

      LABEL: sh '/bin/perl abc def'
      

      which may break down:

      FOO:
      def x = 1;
      for (...) {
          ...
      }
      

          [JENKINS-26107] Allow stage to operate as a labelled block

          Jesse Glick added a comment -

          Probably requires JENKINS-26156 to be fixed before a display name can be associated with the block.

          Jesse Glick added a comment - Probably requires JENKINS-26156 to be fixed before a display name can be associated with the block.

          Code changed in jenkins
          User: Jesse Glick
          Path:
          pom.xml
          src/main/java/org/jenkinsci/plugins/workflow/cps/CpsStepContext.java
          src/main/java/org/jenkinsci/plugins/workflow/cps/CpsThreadGroup.java
          http://jenkins-ci.org/commit/workflow-cps-plugin/9b2acc778065bba8232fbb5dd6255c0d53d73098
          Log:
          JENKINS-26107 StepContext.hasBody implementation.

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: pom.xml src/main/java/org/jenkinsci/plugins/workflow/cps/CpsStepContext.java src/main/java/org/jenkinsci/plugins/workflow/cps/CpsThreadGroup.java http://jenkins-ci.org/commit/workflow-cps-plugin/9b2acc778065bba8232fbb5dd6255c0d53d73098 Log: JENKINS-26107 StepContext.hasBody implementation.

          Code changed in jenkins
          User: Jesse Glick
          Path:
          pom.xml
          src/main/java/org/jenkinsci/plugins/workflow/cps/CpsStepContext.java
          src/main/java/org/jenkinsci/plugins/workflow/cps/CpsThreadGroup.java
          http://jenkins-ci.org/commit/workflow-cps-plugin/891a1bd99a424d82798367e9dd1abed687b752f4
          Log:
          Merge pull request #10 from jglick/optional-block-JENKINS-26107

          JENKINS-26107 StepContext.hasBody implementation

          Compare: https://github.com/jenkinsci/workflow-cps-plugin/compare/3868a9714fd5...891a1bd99a42

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: pom.xml src/main/java/org/jenkinsci/plugins/workflow/cps/CpsStepContext.java src/main/java/org/jenkinsci/plugins/workflow/cps/CpsThreadGroup.java http://jenkins-ci.org/commit/workflow-cps-plugin/891a1bd99a424d82798367e9dd1abed687b752f4 Log: Merge pull request #10 from jglick/optional-block- JENKINS-26107 JENKINS-26107 StepContext.hasBody implementation Compare: https://github.com/jenkinsci/workflow-cps-plugin/compare/3868a9714fd5...891a1bd99a42

          Michael Neale added a comment -

          Can labelled blocks be nested? if so, why? What is the concrete use case for this? (if they are allowed, it has made things more complicated than they were before, when there were no block scoping).

          cc abayer

          Michael Neale added a comment - Can labelled blocks be nested? if so, why? What is the concrete use case for this? (if they are allowed, it has made things more complicated than they were before, when there were no block scoping). cc abayer

          Chris Garman added a comment -

          Hi jglick I think this was assigned to me in error.

          Chris Garman added a comment - Hi jglick I think this was assigned to me in error.

          Code changed in jenkins
          User: Jesse Glick
          Path:
          pom.xml
          src/main/java/org/jenkinsci/plugins/workflow/support/steps/StageStep.java
          src/main/java/org/jenkinsci/plugins/workflow/support/steps/StageStepExecution.java
          src/main/resources/org/jenkinsci/plugins/workflow/support/steps/StageStep/config.jelly
          src/main/resources/org/jenkinsci/plugins/workflow/support/steps/StageStep/help-concurrency.html
          src/main/resources/org/jenkinsci/plugins/workflow/support/steps/StageStep/help.html
          src/main/resources/org/jenkinsci/plugins/workflow/support/steps/stage/Messages.properties
          src/test/java/org/jenkinsci/plugins/workflow/support/steps/StageStepConfigTest.java
          src/test/java/org/jenkinsci/plugins/workflow/support/steps/StageStepTest.java
          http://jenkins-ci.org/commit/pipeline-stage-step-plugin/114b000eb50d39e132b6493fed207321ef49a5bc
          Log:
          [FIXED JENKINS-26107] stage may now take a block; the original mode is deprecated.

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: pom.xml src/main/java/org/jenkinsci/plugins/workflow/support/steps/StageStep.java src/main/java/org/jenkinsci/plugins/workflow/support/steps/StageStepExecution.java src/main/resources/org/jenkinsci/plugins/workflow/support/steps/StageStep/config.jelly src/main/resources/org/jenkinsci/plugins/workflow/support/steps/StageStep/help-concurrency.html src/main/resources/org/jenkinsci/plugins/workflow/support/steps/StageStep/help.html src/main/resources/org/jenkinsci/plugins/workflow/support/steps/stage/Messages.properties src/test/java/org/jenkinsci/plugins/workflow/support/steps/StageStepConfigTest.java src/test/java/org/jenkinsci/plugins/workflow/support/steps/StageStepTest.java http://jenkins-ci.org/commit/pipeline-stage-step-plugin/114b000eb50d39e132b6493fed207321ef49a5bc Log: [FIXED JENKINS-26107] stage may now take a block; the original mode is deprecated.

          Jesse Glick added a comment -

          Was not merged to master, the JIRA link daemon is just getting ahead of itself.

          Jesse Glick added a comment - Was not merged to master , the JIRA link daemon is just getting ahead of itself.

          Code changed in jenkins
          User: Sam Van Oort
          Path:
          pom.xml
          src/main/java/org/jenkinsci/plugins/workflow/support/steps/StageStep.java
          src/main/java/org/jenkinsci/plugins/workflow/support/steps/StageStepExecution.java
          src/main/resources/org/jenkinsci/plugins/workflow/support/steps/StageStep/config.jelly
          src/main/resources/org/jenkinsci/plugins/workflow/support/steps/StageStep/help-concurrency.html
          src/main/resources/org/jenkinsci/plugins/workflow/support/steps/StageStep/help.html
          src/main/resources/org/jenkinsci/plugins/workflow/support/steps/stage/Messages.properties
          src/test/java/org/jenkinsci/plugins/workflow/support/steps/StageStepConfigTest.java
          src/test/java/org/jenkinsci/plugins/workflow/support/steps/StageStepTest.java
          http://jenkins-ci.org/commit/pipeline-stage-step-plugin/d6a220b262424bdf0f6ffd515eac397390e94cd4
          Log:
          Merge pull request #5 from jenkinsci/block-step-JENKINS-26107

          JENKINS-26107 stage may now take a block

          Compare: https://github.com/jenkinsci/pipeline-stage-step-plugin/compare/4711a8009a87...d6a220b26242

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Sam Van Oort Path: pom.xml src/main/java/org/jenkinsci/plugins/workflow/support/steps/StageStep.java src/main/java/org/jenkinsci/plugins/workflow/support/steps/StageStepExecution.java src/main/resources/org/jenkinsci/plugins/workflow/support/steps/StageStep/config.jelly src/main/resources/org/jenkinsci/plugins/workflow/support/steps/StageStep/help-concurrency.html src/main/resources/org/jenkinsci/plugins/workflow/support/steps/StageStep/help.html src/main/resources/org/jenkinsci/plugins/workflow/support/steps/stage/Messages.properties src/test/java/org/jenkinsci/plugins/workflow/support/steps/StageStepConfigTest.java src/test/java/org/jenkinsci/plugins/workflow/support/steps/StageStepTest.java http://jenkins-ci.org/commit/pipeline-stage-step-plugin/d6a220b262424bdf0f6ffd515eac397390e94cd4 Log: Merge pull request #5 from jenkinsci/block-step- JENKINS-26107 JENKINS-26107 stage may now take a block Compare: https://github.com/jenkinsci/pipeline-stage-step-plugin/compare/4711a8009a87...d6a220b26242

          Sam Van Oort added a comment -

          Released as pipeline-stage-step plugin v 2.2

          Sam Van Oort added a comment - Released as pipeline-stage-step plugin v 2.2

          Code changed in jenkins
          User: Jesse Glick
          Path:
          src/main/js/samples.js
          src/main/resources/org/jenkinsci/plugins/workflow/cps/CpsFlowDefinition/help-script.html
          src/main/webapp/snippets/workflow.js
          src/test/java/org/jenkinsci/plugins/workflow/cps/SnippetizerTest.java
          http://jenkins-ci.org/commit/workflow-cps-plugin/a689f3d73d6fc8dcfbe2de270ea37b3f7f68e1b4
          Log:
          JENKINS-26107 Update documentation, examples, and tests to work with a blocky stage.

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: src/main/js/samples.js src/main/resources/org/jenkinsci/plugins/workflow/cps/CpsFlowDefinition/help-script.html src/main/webapp/snippets/workflow.js src/test/java/org/jenkinsci/plugins/workflow/cps/SnippetizerTest.java http://jenkins-ci.org/commit/workflow-cps-plugin/a689f3d73d6fc8dcfbe2de270ea37b3f7f68e1b4 Log: JENKINS-26107 Update documentation, examples, and tests to work with a blocky stage.

          Code changed in jenkins
          User: Jesse Glick
          Path:
          pom.xml
          src/main/js/samples.js
          src/main/resources/org/jenkinsci/plugins/workflow/cps/Snippetizer/help.jelly
          src/main/webapp/snippets/workflow.js
          src/test/java/org/jenkinsci/plugins/workflow/cps/SnippetizerTest.java
          http://jenkins-ci.org/commit/workflow-cps-plugin/4969ce0d0731e097e6ec9cf7c4c95cab2929553f
          Log:
          Merge pull request #11 from jglick/stage-examples-JENKINS-26107

          JENKINS-26107 Examples for blocky stage

          Compare: https://github.com/jenkinsci/workflow-cps-plugin/compare/58f9da35d85e...4969ce0d0731

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: pom.xml src/main/js/samples.js src/main/resources/org/jenkinsci/plugins/workflow/cps/Snippetizer/help.jelly src/main/webapp/snippets/workflow.js src/test/java/org/jenkinsci/plugins/workflow/cps/SnippetizerTest.java http://jenkins-ci.org/commit/workflow-cps-plugin/4969ce0d0731e097e6ec9cf7c4c95cab2929553f Log: Merge pull request #11 from jglick/stage-examples- JENKINS-26107 JENKINS-26107 Examples for blocky stage Compare: https://github.com/jenkinsci/workflow-cps-plugin/compare/58f9da35d85e...4969ce0d0731

          Ryan Campbell added a comment -

          For those like me who are confused: the story is called "labeled block" but was actually fixed by allowing the stage step to accept a block (which we call 'block-scoped stage step').

          Ryan Campbell added a comment - For those like me who are confused: the story is called "labeled block" but was actually fixed by allowing the stage step to accept a block (which we call 'block-scoped stage step').

          Alexander A added a comment -

          > FlowGraphTable should hide the body of the label step by default.
          Doesn't work as well...

          Alexander A added a comment - > FlowGraphTable should hide the body of the label step by default. Doesn't work as well...

          Sam Van Oort added a comment -

          jimilian I think that behavior was changed since the original implementation.

          Sam Van Oort added a comment - jimilian I think that behavior was changed since the original implementation.

          I haven't installed the latest released version but any idea what the code will look like for it?

          mohamed badran added a comment - I haven't installed the latest released version but any idea what the code will look like for it?

          Michael Neale added a comment -

          mbadran by code do you mean pipeline itself?

          If so:

          stage "first"
             sh "echo 42"
             echo "hey"
          

          would become:

          stage("first") {
            sh "echo 42"
            echo "hey"
          }
          

          that is about all there is to it.

          Michael Neale added a comment - mbadran by code do you mean pipeline itself? If so: stage "first" sh "echo 42" echo "hey" would become: stage("first") { sh "echo 42" echo "hey" } that is about all there is to it.

          michaelneale Thanks for help

          I've tried out something which seems to have broken blue ocean, and i thought that I will be able to have a specific label for the shell script but this didn't happen. Also the support for this in stage view doesn't seem to be pretty good.

          Here is the code I've created
          def test = [:]

          test["a"] = {
          stage ("a") {
          stage ("ab")

          { sh "echo stage abc" }

          stage ("xyz")

          { sh "echo stage xyz" }

          }
          }

          test["b"] = {
          stage ("b") {
          stage ("bb")

          { sh "echo stage bb" }

          stage ("bxz")

          { sh "echo stage bxz" }

          }
          }
          node {
          //stage 'start'
          parallel test
          stage ('middle')

          { sh "echo middle" }

          }

          This code actually breaks blue-ocean from showing the workflow, and it shows now the log only as attached basically i wanted to group each shell script in a separate label since it seems there are no way to change "Shell Script" from showing up. This also shows multiple stages inside stage view which is really ugly as attached

          mohamed badran added a comment - michaelneale Thanks for help I've tried out something which seems to have broken blue ocean, and i thought that I will be able to have a specific label for the shell script but this didn't happen. Also the support for this in stage view doesn't seem to be pretty good. Here is the code I've created def test = [:] test ["a"] = { stage ("a") { stage ("ab") { sh "echo stage abc" } stage ("xyz") { sh "echo stage xyz" } } } test ["b"] = { stage ("b") { stage ("bb") { sh "echo stage bb" } stage ("bxz") { sh "echo stage bxz" } } } node { //stage 'start' parallel test stage ('middle') { sh "echo middle" } } This code actually breaks blue-ocean from showing the workflow, and it shows now the log only as attached basically i wanted to group each shell script in a separate label since it seems there are no way to change "Shell Script" from showing up. This also shows multiple stages inside stage view which is really ugly as attached

          Michael Neale added a comment -

          mbadran can you put that in a differnet ticket under the "blueocean-plugin" component? It fails to showing just the log so you see something. nested stages aren't well supported yet, so would need to decide how to lay that out.

          Michael Neale added a comment - mbadran can you put that in a differnet ticket under the "blueocean-plugin" component? It fails to showing just the log so you see something. nested stages aren't well supported yet, so would need to decide how to lay that out.

          michaelneale Ok, I've created new issue about this JENKINS-38442

          mohamed badran added a comment - michaelneale Ok, I've created new issue about this JENKINS-38442

          Kyle Flavin added a comment -

          Is the concurrency parameter no longer available? I'm converting some legacy code to use the new format. We have a lot of stuff that looks like this:

          stage name: 's1: do something', concurrency: 1
          ...
          stage name: 's2: do something else', concurrency: 1
          ...

          Maybe it's not necessary since we're setting the concurrency to "1" anyway?

          Kyle Flavin added a comment - Is the concurrency parameter no longer available? I'm converting some legacy code to use the new format. We have a lot of stuff that looks like this: stage name: 's1: do something', concurrency: 1 ... stage name: 's2: do something else', concurrency: 1 ... Maybe it's not necessary since we're setting the concurrency to "1" anyway?

          Owen Mehegan added a comment -

          kflavin concurrency as a parameter to the stage step is deprecated, in favor of the milestone step. See https://wiki.jenkins-ci.org/display/JENKINS/Pipeline+Stage+Step+Plugin and https://wiki.jenkins-ci.org/display/JENKINS/Pipeline+Milestone+Step+Plugin

          Owen Mehegan added a comment - kflavin concurrency as a parameter to the stage step is deprecated, in favor of the milestone step. See https://wiki.jenkins-ci.org/display/JENKINS/Pipeline+Stage+Step+Plugin and https://wiki.jenkins-ci.org/display/JENKINS/Pipeline+Milestone+Step+Plugin

          Alex S. added a comment -

          this ticket is resolved, but for me it's really not clear how i can now label single sh steps?

          Can you give me a code example?

          Alex S. added a comment - this ticket is resolved, but for me it's really not clear how i can now label single sh steps? Can you give me a code example?

          Sam Van Oort added a comment -

          mac110 

          stage('named') {
            sh 'my special shell step'
          }

          Sam Van Oort added a comment - mac110   stage( 'named' ) { sh 'my special shell step' }

          Greg Knapp added a comment -

          So we should use a `stage` block for each command we want to label? Seems like that would lead to a verbose Jenkinsfile

          Greg Knapp added a comment - So we should use a `stage` block for each command we want to label? Seems like that would lead to a verbose Jenkinsfile

          Yes, possibly. But you generally wouldn't "label a command", probably more a couple of them to produce not just a serie of staged named after the called commands, but that stage is actually doing ("checking code coverage" or whatever).

          Baptiste Mathus added a comment - Yes, possibly. But you generally wouldn't "label a command", probably more a couple of them to produce not just a serie of staged named after the called commands, but that stage is actually doing ("checking code coverage" or whatever).

          Greg Knapp added a comment -

          What about being able to label a script block, so you can group several commands and display it as a single operation?

          Greg Knapp added a comment - What about being able to label a script block, so you can group several commands and display it as a single operation?

          batmat I actually used other CI solutions where it naming an "sh" operation was very useful. 

          Marcello de Sales added a comment - batmat I actually used other CI solutions where it naming an "sh" operation was very useful. 

            jglick Jesse Glick
            jglick Jesse Glick
            Votes:
            44 Vote for this issue
            Watchers:
            80 Start watching this issue

              Created:
              Updated:
              Resolved: