0

我正在尝试将 Jenkins 2.0 与管道插件一起使用。如何FreeStyleProject并行执行多个任务(s)(通过闭包)。

我尝试了 2 个示例,但都失败了。我怎样才能实现这个功能?

A. 示例流水线脚本;

def taskNames = [
    "Test FSP 1",
    "Test FSP 2"
]

buildClosures = [:]
for (taskName in taskNames) {
    echo "iterating... taskName is: ${taskName}"
    def curClosure = {
        echo "inside curClosure... taskName is: ${taskName}"
        build(taskName)
    }
    buildClosures.put(taskName, curClosure)
}

parallel(buildClosures)

这是输出(最后一项构建了两次,第一个变量似乎被覆盖了);

Started by user Cagri Celebi
[Pipeline] echo
iterating... taskName is: Test FSP 1
[Pipeline] echo
iterating... taskName is: Test FSP 2
[Pipeline] Execute in parallel : Start
[Pipeline] [Test FSP 1] parallel { (Branch: Test FSP 1)
[Pipeline] [Test FSP 2] parallel { (Branch: Test FSP 2)
[Pipeline] [Test FSP 1] echo
[Test FSP 1] inside curClosure... taskName is: Test FSP 2
[Pipeline] [Test FSP 1] build (Building Test FSP 2)
[Test FSP 1] Scheduling project: Test FSP 2
[Pipeline] [Test FSP 2] echo
[Test FSP 2] inside curClosure... taskName is: Test FSP 2
[Pipeline] [Test FSP 2] build (Building Test FSP 2)
[Test FSP 2] Scheduling project: Test FSP 2

[Test FSP 1] Starting building: Test FSP 2 #13
[Pipeline] } //parallel
[Pipeline] } //parallel
[Pipeline] Execute in parallel : End
[Pipeline] End of Pipeline
Finished: SUCCESS

B. 这个也失败了;

subjobIteration = [:]
["Test FSP 1","Test FSP 2"].each{ jobName ->
  subjobIteration.put(jobName,{build( jobName )})
}
parallel( subjobIteration )

输出仅包含第一项;

Started by user Cagri Celebi
[Pipeline] Execute in parallel : Start
[Pipeline] [Test FSP 1] parallel { (Branch: Test FSP 1)
[Pipeline] [Test FSP 1] build (Building Test FSP 1)
[Test FSP 1] Scheduling project: Test FSP 1

[Test FSP 1] Starting building: Test FSP 1 #3
[Pipeline] } //parallel
[Pipeline] Execute in parallel : End
[Pipeline] End of Pipeline
Finished: SUCCESS
4

0 回答 0