Jenkins Custom Workspaces are not created for Parallel Stages created inside the Pipeline Script
Only the main Custom Workspace "main_ws" is created.
Why are Custom Workspaces for parallel script-generated stages not created and how can I fix this?
def getTests(Name, Versions) {
return Versions.collectEntries { version ->
[
(version): {
stage("${Name}:${version} Tests") {
agent {
node {
label "docker"
customWorkspace "${Name}${version}"
}
}
script {
bat "echo Testing the ${Name}:${version}"
}
}
}
]
}
}
pipeline {
agent {
label "docker"
}
tools {
gradle "gradle"
}
parameters {
text(name: 'VERSIONS', defaultValue: '1.0\n2.0\n3.0\n', description: '')
booleanParam(name: 'NAME', defaultValue: false, description: '')
}
stages {
stage('Tests') {
parallel {
stage('Tests') {
when {
expression {
return params.NAME
}
}
agent {
node {
label "docker"
customWorkspace "main_ws"
}
}
steps {
script {
def versions = params.VERSIONS.split("\n")
parallel getTests("NAME", versions)
}
}
}
}
}
}
}
Declarative syntax inside scripted syntax doesn't work the same way as outside. Outside the
scriptsteppipelineandstageare keywords and acceptagentkeyword. Inside thescriptsteppipelineandstageare steps that know nothingagentkeyword anymore. The corresponding scripted syntax isnodeandws, see here.