Search code examples
jenkinsjenkins-pluginsjenkins-pipeline

Trigger Multibranch Job from another


I have a job in Jenkins and I need to trigger another one when it ends (if it ends right).

The second job is a multibranch, so I want to know if there's any way to, when triggering this job, pass the branch I want to. For example, if I start the first job in the branch develop, I need it to trigger the second one for the develop branch also.

Is there any way to achieve this?


Solution

  • Just think about the multibranch job being a folder containing the real jobs named after the available branches:

    Using Pipeline Job

    When using the pipeline build step you'll have to use something like: build(job: 'JOB_NAME/BRANCH_NAME'). Of course you may use a variable to specify the branch name.

    Using Freestyle Job

    When triggering from a Freestyle job you most probably have to

    1. Use the parameterized trigger plugin as the plain old downstream build plugin still has issues triggering pipeline jobs (at least the version we're using)
    2. As job name use the same pattern as described above: JOB_NAME/BRANCH_NAME

    Should be possible to use a job parameter to specify the branch name here. However I didn't give it a try, though.