Сбой параллели Jenkins при запуске функции из импортированного класса с картой:
java.lang.IllegalArgumentException: Expected a closure or failFast but found dev=automation_dev
Конвейер:
#!/usr/bin/env groovy
@Library('SharedLibraries@master') _
def lib = new com.jenkins.dir()
pipeline {
agent {
node {
label "master"
}
}
parameters {
string(defaultValue: "automation", description: '', name: 'createdir')
}
stages {
stage('Create dir') {
steps {
script {
parallel lib.parallelCreateDir(createdir, this)
}
}
}
}
post {
always {
script {
deleteDir()
cleanWs()
}
}
}
}
В src / com / jenkins / dir. groovy
package com.jenkins
class dir {
// need to create constructor to use below variables or methods
public dir() {
}
// variable for the environments
def profiles = ["dev", "stg", "prod"]
// variables converted to map
def parallelCreateDir(String createdir, caller) {
profiles.collectEntries { it ->
caller.stage("Generate: ${it}") {
caller.echo "${createdir}_${it}"
}
["${it}": "${createdir}_${it}"]
}
}
}
В целом метод работает, потому что печать каталогов, но до конца не удалось:
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Create dir)
[Pipeline] script
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Generate: dev)
[Pipeline] echo
automation_dev
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Generate: stg)
[Pipeline] echo
automation_stg
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Generate: prod)
[Pipeline] echo
automation_prod
[Pipeline] }
[Pipeline] // stage
[Pipeline] parallel
[Pipeline] // parallel
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // stage
[Pipeline] End of Pipeline
java.lang.IllegalArgumentException: Expected a closure or failFast but found dev=automation_dev
at org.jenkinsci.plugins.workflow.cps.steps.ParallelStep$DescriptorImpl.newInstance(ParallelStep.java:278)
at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:266)