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

Allow stage to operate as a labelled block

    XMLWordPrintable

Details

    Description

      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 (...) {
          ...
      }
      

      Attachments

        Issue Links

          Activity

            jglick Jesse Glick added a comment -

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

            jglick 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_issue_link 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_issue_link 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
            michaelneale 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

            michaelneale 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
            chrisoneiota Chris Garman added a comment -

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

            chrisoneiota 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_issue_link 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.
            jglick Jesse Glick added a comment -

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

            jglick 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_issue_link 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
            svanoort Sam Van Oort added a comment -

            Released as pipeline-stage-step plugin v 2.2

            svanoort 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_issue_link 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_issue_link 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
            recampbell 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').

            recampbell 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').
            jimilian Alexander A added a comment -

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

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

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

            svanoort 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?

            mbadran mohamed badran added a comment - I haven't installed the latest released version but any idea what the code will look like for it?
            michaelneale 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 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

            mbadran 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
            michaelneale 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 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

            mbadran mohamed badran added a comment - michaelneale Ok, I've created new issue about this JENKINS-38442
            kflavin 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?

            kflavin 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?
            owenmehegan 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

            owenmehegan 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
            mac110 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?

            mac110 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?
            svanoort Sam Van Oort added a comment -

            mac110 

            stage('named') {
              sh 'my special shell step'
            }
            svanoort Sam Van Oort added a comment - mac110   stage( 'named' ) { sh 'my special shell step' }
            greg_k 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_k 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).

            batmat 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_k 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_k 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. 

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

            People

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

              Dates

                Created:
                Updated:
                Resolved: