[英]Calling multiple downstream jobs from an upstream Jenkins pipeline job
I have two pipeline based jobs我有两个基于管道的工作
Parent_Job (has string parameters project1 & project2) Parent_Job(具有字符串参数 project1 和 project2)
@NonCPS
def invokeDeploy(map) {
for (entry in map) {
echo "Starting ${entry.key}"
build job: 'Child_Job', parameters: [
string(name: 'project', value: entry.key),
string(name: 'version', value: entry.value)
], quietPeriod: 2, wait: true
echo "Completed ${entry.key}"
}
}
pipeline {
agent any
stages {
stage('Test') {
steps {
script {
invokeDeploy(params)
}
}
}
}
}
Child_Job (has string parameters project & version) Child_Job(具有字符串参数项目和版本)
pipeline {
agent any
stages {
stage('Test') {
steps {
script {
echo "${params.project} --> ${params.version}"
}
}
}
}
}
Parent job output父作业输出
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Test)
[Pipeline] script
[Pipeline] {
[Pipeline] echo
Starting project2
[Pipeline] build (Building Child_Job)
Scheduling project: Child_Job
Starting building: Child_Job #18
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS
I expected the downstream job to be called twice, (for project1 and project2) but its invoked only once (for project2)我希望下游作业被调用两次(对于项目 1 和项目 2),但它只被调用一次(对于项目 2)
Is there something obviously wrong with this script?这个脚本有什么明显的问题吗?
It seems that the problem with wait: true
option enabled for build job
step.似乎为build job
步骤启用了wait: true
选项的问题。 If you change it to wait: false
it will execute 2 times.如果将其更改为wait: false
它将执行 2 次。 I tried it on this test pipeline:我在这个测试管道上试过:
@NonCPS
def invokeDeploy(map) {
for (entry in map) {
echo "Starting ${entry.key}"
build job: 'pipeline', quietPeriod: 2, wait: false
echo "Completed ${entry.key}"
}
}
pipeline {
agent any
stages {
stage('Test') {
steps {
script {
def sampleMap = [first_job:'First', second_job:'Second']
invokeDeploy(sampleMap)
}
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.