简体   繁体   English

从上游 Jenkins 管道作业调用多个下游作业

[英]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.

相关问题 如何在詹金斯中将参数作为环境变量从上游作业传递到下游作业? 无需对下游工作进行参数化 - How to pass parameter as environment variable from upstream job to downstream job in jenkins? without downstream jobs being parametrized 当有多个上游作业时,Jenkins从上游作业复制工件 - Jenkins copy artifacts from upstream job when there are multiple upstream jobs Jenkins 管道:如果上游作业不存在,则防止作业失败 - Jenkins pipeline: prevent a job from failing if upstream jobs do not exist Jenkins的上游和下游工作 - Upstream and DownStream Job on Jenkins Jenkins矩阵作业未触发多个下游作业 - Jenkins matrix job not triggering multiple downstream jobs Jenkins:基于多个上游作业触发单个下游作业 - Jenkins : Trigger Single Downstream job based on multiple upstream job 使用多个上游作业的版本参数化Jenkins作业 - Parameterizing a Jenkins job with the versions of multiple upstream jobs 詹金斯管道下游工作-在特定阶段继续下一个工作 - Jenkins Pipeline Downstream Jobs - continue with next job at specific stage 如果下游作业失败,如何使主詹金斯管道作业失败 - How to fail master Jenkins pipeline job if downstream jobs fails Jenkins 将工件从上游作业复制到下游并返回 - Jenkins Copy Artifacts from Upstream Job to Downstream and back
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM