Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 707
Jaime Alcántara Arnela Avatar asked Jun 18 '18 12:06

Jaime Alcántara Arnela


People also ask

Which of the below could be the use case of Multibranch pipeline?

It can be use used for Gitlab, Bitbucket teams, or Gitea organization. Mullitbranch pipleine can only configure pipelines for a single Git repository. Whereas a Jenins Github organization project can automatically configure multi-branch pipelines for all the repos in a Github organization.

How do I trigger one Jenkins job from another?

Select a job that triggers a remote one and then go to Job Configuration > Build section > Add Build Step > Trigger builds on remote/local projects option. This configuration allows you to trigger another exciting job on a different CM (remote). The downstream job name part will autocomplete.


1 Answers

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.

like image 94
Joerg S Avatar answered Sep 22 '22 19:09

Joerg S