I am trying to get a Jenkins (2.204.2) declarative pipeline to run parallel stages generated into a map on different machines. I am aware it can be done by mixing in the script
block and I have done it that way in the past, but from documentation and other Stack____ questions I cannot figure out why this format does not work.
I have stripped everything down as far as possible and I am trying to just create the map statically outside the pipeline to figure out the syntax I need.
#!/usr/bin/env groovy
def map = [:]
map['Passed Stage'] = {
stage("Passed Map Inner Stage"){
agent{ label "nodeLabel" }
steps{
echo "PASSED MAP STEP"
}
}
}
pipeline {
agent { label "nodeLabel" }
stages {
stage("Non map stage"){
agent{ label "nodeLabel" }
steps{
echo "NON MAP STEP"
}
}
stage("Direct Map Outer Parallel Stage"){
parallel{ direct :
stage("Direct Map Inner Stage"){
agent{ label "nodeLabel" }
steps{
echo "DIRECT MAP STEP"
}
}
}
}
stage("Passed Map Outer Parallel Stage"){
parallel{ map }
}
}
}
The first two stage methods work if I comment out the mapped one but "Passed Map Outer Parallel Stage" always fails with:
Running in Durability level: MAX_SURVIVABILITY
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 33: Expected a stage @ line 33, column 23.
parallel{ map }
^
WorkflowScript: 33: No stages specified @ line 33, column 13.
parallel{ map }
^
WorkflowScript: 33: No stages specified @ line 33, column 13.
parallel{ map }
^
3 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:142)
at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:127)
at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:561)
at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:522)
at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:327)
at hudson.model.ResourceController.execute(ResourceController.java:97)
at hudson.model.Executor.run(Executor.java:427)
Finished: FAILURE
The stage format seems fine from everything I've spent reading all day, and passing the same stage directly to parallel
outside the map works fine.
What am I missing here? why won't parallel
accept my map? Does declarative parallel
only accept stages statically passed? Is my Jenkins version too low?