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

Ability to create custom stages in parallel blocks in pipeline shared library

      I would like to be able to easily run the same steps across multiple nodes using the declarative pipeline and a shared library. This does not currently seem to be possible since only custom steps can be created in shared libraries.

       

      Example jenkinsfile:

      pipeline {
          agent any
          stages {
              stage('Build everywhere') {
                  runOnAllPlatforms {
                      sh 'doing build things'
                  }
              }
          }
      }

      Example shared library vars/runOnAllPlatforms.groovy:

      def call(Closure body) {
          parallel {
              stage('RHEL') {
                  agent {
                      node { label 'rhel7' }
                  }
                  steps {
                      body()
                  }
              stage('Apple') {
              agent {
                  node { label 'apple' }
              }
              steps {
                  body()
              }
              steps {
                  body()
              }
          }
      }

          [JENKINS-49662] Ability to create custom stages in parallel blocks in pipeline shared library

          kevlan I'm getting the following error: ": Starting with version 0.5, steps in a stage must be in a steps block.

          Any reason why? I'm reusing your example...

          pipeline {
          
            agent any
          
            stages {
          
              stage('Build everywhere') {
               runOnAllPlatforms {
                 sh 'doing build things'
               }
            }
          }

           

          The error is the following:

           

           

          Branch indexing
          Connecting to https://github.intuit.com/api/v3 using mdesales/****** (GitHub Enterprise Access Token)
          Obtained Jenkinsfile from 3d42560bb3044468f1acd3c75f1d904e5df15247
          Running in Durability level: MAX_SURVIVABILITY
          
          GitHub has been notified of this commit’s build result
          
          org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
          WorkflowScript: 9: Unknown stage section "runOnAllPlatforms". Starting with version 0.5, steps in a stage must be in a steps block. @ line 9, column 5.
                 stage('Build everywhere') {
                 ^
          
          WorkflowScript: 9: No "steps" or "parallel" to execute within stage "Build everywhere" @ line 9, column 5.
                 stage('Build everywhere') {
                 ^
          
          2 errors
          
          	at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310)
          	at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1085)
          	at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:603)
          	at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:581)
          	at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:558)
          	at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298)
          	at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268)
          	at groovy.lang.GroovyShell.parseClass(GroovyShell.java:688)
          	at groovy.lang.GroovyShell.parse(GroovyShell.java:700)
          	at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.doParse(CpsGroovyShell.java:133)
          	at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:127)
          	at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:557)
          	at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:518)
          	at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:290)
          	at hudson.model.ResourceController.execute(ResourceController.java:97)
          	at hudson.model.Executor.run(Executor.java:429)
          Finished: FAILURE

           

          Marcello de Sales added a comment - kevlan I'm getting the following error: ": Starting with version 0.5, steps in a stage must be in a steps block. Any reason why? I'm reusing your example... pipeline { agent any stages { stage( 'Build everywhere' ) { runOnAllPlatforms { sh 'doing build things' } } }   The error is the following:     Branch indexing Connecting to https: //github.intuit.com/api/v3 using mdesales/****** (GitHub Enterprise Access Token) Obtained Jenkinsfile from 3d42560bb3044468f1acd3c75f1d904e5df15247 Running in Durability level: MAX_SURVIVABILITY GitHub has been notified of this commit’s build result org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: WorkflowScript: 9: Unknown stage section "runOnAllPlatforms" . Starting with version 0.5, steps in a stage must be in a steps block. @ line 9, column 5. stage( 'Build everywhere' ) { ^ WorkflowScript: 9: No "steps" or "parallel" to execute within stage "Build everywhere" @ line 9, column 5. stage( 'Build everywhere' ) { ^ 2 errors at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310) at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1085) at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:603) at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:581) at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:558) at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298) at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268) at groovy.lang.GroovyShell.parseClass(GroovyShell.java:688) at groovy.lang.GroovyShell.parse(GroovyShell.java:700) at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.doParse(CpsGroovyShell.java:133) at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:127) at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:557) at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:518) at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:290) at hudson.model.ResourceController.execute(ResourceController.java:97) at hudson.model.Executor.run(Executor.java:429) Finished: FAILURE  

          Kevin Lannen added a comment -

          Yes, there's a very good reason why the code won't work. I wrote that code to demonstrate what how I would like the API to work as a feature request, not as code that currently works hence why this feature request exists.

          Kevin Lannen added a comment - Yes, there's a very good reason why the code won't work. I wrote that code to demonstrate what how I would like the API to work as a feature request, not as code that currently works hence why this feature request exists.

          kevlan The status says RESOLVED ... shouldn't it be changed then?

          Marcello de Sales added a comment - kevlan The status says RESOLVED  ... shouldn't it be changed then?

          OOps as a duplicate... 

          Marcello de Sales added a comment - OOps as a duplicate... 

          Kevin Lannen added a comment -

          This functionality is available with the scripted syntax if that's what you are trying to do though.

          Kevin Lannen added a comment - This functionality is available with the scripted syntax if that's what you are trying to do though.

          Liam Newman added a comment -

          Bulk closing resolved issues.

          Liam Newman added a comment - Bulk closing resolved issues.

            Unassigned Unassigned
            kevlan Kevin Lannen
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: