3

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?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
sebachili
  • 123
  • 1
  • 3
  • 10
  • I think it is wiser to solve the problem with your unittests, not hack around that. – Rik Jan 18 '17 at 08:49

1 Answers1

4

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.

bp2010
  • 2,342
  • 17
  • 34