简体   繁体   English

Jenkins Build Flow Plugin 依次并行地链接多个作业

[英]Jenkins Build Flow Plugin sequentially chain multiple jobs in parallel

I'm attempting to replicate this functionality from the Build Flow Plugin: https://wiki.jenkins-ci.org/display/JENKINS/Build+Flow+Plugin :我正在尝试从 Build Flow 插件中复制此功能: https://wiki.jenkins-ci.org/display/JENKINS/Build+Flow+Plugin

parallel (
    {
        build("job1")
        build("job2")
    },
    {
        build("job5")
        build("job6")
    }
)

I have the following DSL job:我有以下 DSL 工作:

subjob = "test"
subjob2 = "test2"
series1 = []
series2 = []
subjob = []

["job1","job2"].each{ parameter ->
  series1.add({build( subjob, param: parameter )})
}

["job5","job6"].each{ parameter2 ->
  series2.add({build( subjob2, param: parameter2)})
}

subjob.add(series1)
subjob.add(series2)

parallel( subjob )

My goal is to run one set of jobs 1&2 in series and another set of jobs 5&6 in series, but to run both sets of jobs in parallel.我的目标是依次运行一组作业 1&2 和另一组作业 5&6,但要并行运行两组作业。 ie Job 1 and 5 kick off at the same time, then when job 1 finishes job 2 start and when job 5 finishes job 6 starts.即作业 1 和 5 同时开始,然后当作业 1 完成作业 2 时开始,当作业 5 完成作业 6 时开始。

However, I've tried a number of variations on the above code, but different errors each time.但是,我尝试了上述代码的多种变体,但每次都会出现不同的错误。 The above code gives the following:上面的代码给出了以下内容:

ERROR: Failed to run DSL Script
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '[Script1$_run_closure1$_closure3@3c52c84, Script1$_run_closure1$_closure3@56789ba0]' with class 'java.util.ArrayList' to class 'groovy.lang.Closure' due to: groovy.lang.GroovyRuntimeException: failed to invoke constructor: public groovy.lang.Closure(java.lang.Object,java.lang.Object) with arguments: [Script1$_run_closure1$_closure3@3c52c84, Script1$_run_closure1$_closure3@56789ba0] reason: java.lang.InstantiationException

Is there a better way of doing this?有没有更好的方法来做到这一点?

The parallel step / function expects a list of closures, eg a list of code blocks.并行步骤/函数需要一个闭包列表,例如代码块列表。 What you are giving it is a list of list with closures, and naturally you can't cast that to a closure, hence the error:你给它的是一个带有闭包的列表,自然你不能将它转换为闭包,因此出现错误:

Cannot cast object '...' with class 'java.util.ArrayList' to class 'groovy.lang.Closure'

What you need to do is to wrap the serial jobs in a closure:您需要做的是将串行作业包装在一个闭包中:

subjob = "test"
subjob2 = "test2"
series1 = []
series2 = []
subTasks = []

["job1","job2"].each{ parameter ->
  series1.add({build( subjob, param: parameter )})
}

["job5","job6"].each{ parameter2 ->
  series2.add({build( subjob2, param: parameter2)})
}

subTasks.add({
  series1.each{it()}
})
subTasks.add({
  series2.each{it()}
})

parallel( subTasks )

An explanation of what I do:对我所做的解释:

subTasks.add({
  series1.each{it()}
})

First we add a new closure to the list subTasks , this closure takes each element in the list and executes it ( it() ).首先我们向列表subTasks添加一个新的闭包,这个闭包获取列表中的每个元素并执行它( it() )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM