Jenkins multi-branch pipeline and specifying upstream projects

Jenkinsjenkins-pipeline

We currently generate a lot of Jenkins jobs on a per Git branch basis using Jenkins job DSL; the multi-branch pipeline plugin looks like an interesting way to potentially get first-class job generation support using Jenkinsfiles and reduce the amount of Job DSL we maintain.

For example we have libwidget-server and widget-server develop branch projects. When the libwidget-server build finishes then the widget-server job is triggered (for the develop branch). This applies to other branches too.

This makes use of the Build after other projects are built to trigger upon completion of an upstream build (e.g. libwidget-server causes widget-server to be built).

It seems that the multi-branch pipeline plugin lacks the Build after other projects are built setting – how would we accomplish the above in the multi-branch pipeline build?

Best Answer

You should add the branch name to your upstream job (assuming you are using a multi-branch pipeline for the upstream job too).

Suppose you have a folder with two jobs, both multi-branch pipeline jobs: jobA and jobB; jobB should trigger after jobA's master.

You can add this code snippet to jobB's Jenkinsfile:

properties([
  pipelineTriggers([
    upstream(
      threshold: 'SUCCESS',
      upstreamProjects: '../jobA/master'
    )
  ])
])

(Mind that any branch of jobB here will trigger after jobA's master!)