我正在尝试使用以下代码同时运行多个作业,但它是按顺序运行的。一旦第一份工作完成,那么只有它移动到下一个等等。
我可以知道我做错了什么。任何帮助/输入赞赏。 这是代码:
def servers = ["a", "b", "c", "d"];
if ( servers != null )
{
for (i=0; i<servers.size(); i++)
{
if (servers[i] != null)
{
def core = servers[i];
def stageName = "stage${core}"
stage(stageName){
stepsForMainJob[stageName] = { build job: 'mainJob', parameters: [[$class: 'StringParameterValue', name: 'PARAM', value: core]]}
}
}
}
}
parallel stepsForMainJob;
答案 0 :(得分:0)
尝试包括阶段结束,这样你就可以在Jenkins中看到所有阶段一次启动。
def servers = ["a", "b", "c", "d"];
Map jobs = [:]
if ( servers != null ) {
for (i=0; i<servers.size(); i++) {
if (servers[i] != null) {
def core = servers[i];
def stageName = "stage${core}"
jobs.put(stageName, {
stage(stageName) {
build job: 'mainJob', parameters: [[$class: 'StringParameterValue', name: 'PARAM', value: core]]
}
} )
}
}
}
parallel(jobs)
答案 1 :(得分:0)
Thanks for the suggestion, It was scheduling all jobs at the same time, but the build still running sequentially.
Here is the o/p
[Pipeline] parallel
[Pipeline] [stagea] { (Branch: stagea)
[Pipeline] [stageb] { (Branch: stageb)
[Pipeline] [stagec] { (Branch: stagec)
[Pipeline] [stagea] stage
[Pipeline] [stagea] { (stagea)
[Pipeline] [stageb] stage
[Pipeline] [stageb] { (stageb)
[Pipeline] [stagec] stage
[Pipeline] [stagec] { (stagec)
[Pipeline] [stagea] build (Building mainJob)
[stagea] Scheduling project: mainJob
[Pipeline] [stageb] build (Building mainJob)
[stageb] Scheduling project: mainJob
[Pipeline] [stagec] build (Building mainJob)
[stagec] Scheduling project: mainJob
[stagea] Starting building: mainJob #79
[Pipeline] [stagea] }
[Pipeline] [stagea] // stage
[Pipeline] [stagea] }
[stageb] Starting building: mainJob #80
[Pipeline] [stageb] }
[Pipeline] [stageb] // stage
[Pipeline] [stageb] }`enter code here`
[stagec] Starting building: mainJob #81
[Pipeline] [stagec] }
[Pipeline] [stagec] // stage
[Pipeline] [stagec] }
[Pipeline] // parallel
[Pipeline] End of Pipeline
Finished: SUCCESS