Multibranch pipeline - Jenkins - How to execute one branch at a time?

3.2k views Asked by At

Merry xmas guys,

I have got a very basic question that I didn't find out there:

How to build branches one at a time?

I actually have two branches to be built set in my multi-branch pipeline Jenkins process. However, when I hit run, if no changes, both are built at the same time which is a problem due to the unit tests that are using the same port.

This is why I would need to run one branch at a time.

Is there any way in which I can do this?

1

There are 1 answers

2
bp2010 On

You cannot limit branches being built with the Multibranch Pipeline. But you can limit that only one step/stage is being run at a time, even across branches, with a lock

stage("Unit Test") {
  lock("unit_test_lock") {

    //Unit tests here

  } // resource is unlocked.
}

If two branches A and B build concurrently, A will first acquire the lock, while B will wait for the lock to be released. So the branches will never execute this locked stage concurrently.