Jenkins : Trigger Single Downstream job based on multiple upstream job

有些话、适合烂在心里 提交于 2021-01-28 02:02:18

问题


I would like to build a Pipeline in Jenkins where result based on multiple upstream jobs should trigger a single downstream job.

For ex:

Job 1 --> Job 2 -->   Job 5 --> Job 6
          Job 3 -->
          Job 4 -->

Job 1: when a new piece of code is committed to Git production it should trigger Jobs 2,3 and 4 (this part I was able to run run using Build Other jobs option in Post Build Action; although any suggestion to improve this is also greatly appreciated).

Job 2,3 and 4 are regressions to be run on different test machines.

The part I am not able to fig out is only when Job 2,3 and 4 are successful it should trigger the downstream Job 5 and eventually 5 can trigger 6.

I am currently using the Build Pipeline plugin, but it was successful for one (downstream) to many (upstream )jobs and not vice versa.

Any help/suggestion/guidance is greatly appreciated. Thanks in advance! Cheers!!


回答1:


you can do this by using the 'Build after other projects are built' on Job 5 configuration 'Build Triggers' section. There you add Job2, Job3 and Job4 as dependencies and set up the option 'Trigger only if build is stable' (As the image below). This should do the job, and will wait the three jobs to finish.

But this as you said does not accomplish the goal of executing Job5 when Job2,3 and 4 are successful (Job5 gets executed even though one of them failed). I think the best solution for your case is to use a new job and create it as a 'Pipeline' job (let's call it PipelineJob). This way you do not have to edit every single Job with its own configuration and dependencies and you can tweak your pipeline behaviour easier. Also thanks to error propagation it will fail if some phase fails too! This should work as intended:

pipeline {
    agent any
    stages{
        stage('Phase 1') {
            steps {
                build 'Job1'
            }
        }
        stage('Phase 2') {
            parallel {
                stage('Job 2') {
                    steps {
                        build 'Job2'
                    }
                }
                stage('Job 3') {
                    steps {
                        build 'Job3'
                   }
                }
                stage('Job 4') {
                    steps {
                        build 'Job4'
                   }
                }
            }
        }
        stage('Phase 3') {
            steps {
                build 'Job5'
            }
        }
        stage('Phase 4') {
            steps {
                build 'Job6'
            }
        }
    }
}



回答2:


In addition to @CMassa's answer (yes this works - thanks for the answer), I found Join Plugin by Jenkins and it also works great for this scenario.



来源:https://stackoverflow.com/questions/53109101/jenkins-trigger-single-downstream-job-based-on-multiple-upstream-job

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!