title: How to limit Jenkins concurrent multibranch pipeline builds across branches?
body: <p>Does anybody have an idea how to limit concurrent builds with a declarative pipeline set up in a multibranch job across branches?</p>
  
  <p>Anytime we set an agent for a stage, a new executor will be allocated. This leads to deadlocks e.g. when you have builds triggered concurrently for as many branches as you have executors. Not setting an agent leads to the stage chosing an executor randomly, which isn't acceptable as certain stages need to run on certain agents...</p>
  
  <p>The classic approaches don't work:</p>
  
  <ul>
  <li>Throttle Concurrent Builds Plugin doesn't work with multibranch</li>
  <li>Setting <code>properties([disableConcurrentBuilds()])</code> just limits concurrency per branch</li>
  <li>the <code>lock</code> step needs <code>agent none</code> in the pipeline root to prevent allocating executors, but this hinders our global <code>post</code> block to execute suff as it needs an agent and apparently one cannot set an agent for the post block</li>
  </ul>