How can we enable concurrent builds but only if the builds are on different branches?

I would like to enable concurrent builds for the Jenkins job. However i do not want builds for the same branch execute in parallel. Is there a way to acheive this with Jenkins?

You could have a per branch lockable resource if you want to keep a queue

or just disableConcurrentBuilds() if you just want to do a single job/branch. This is the most straight forward, but I believe it’ll end up making multiple jobs into one if more come in while its waiting.

2 Likes

Hi @srirammk and welcome to this community :wave:

I think Jenkins can provide a way to configure concurrent builds while also restricting parallel builds of the same branch. This could be achieved by using the “Throttle Concurrent Builds” plugin. Here are the steps to configure this plugin:

  1. Install the “Throttle Concurrent Builds” plugin on your Jenkins instance.
  2. Go to the configuration page of the job for which you want to enable concurrent builds.
  3. Under the “Build Environment” section, check the “Throttle Concurrent Builds” checkbox.
  4. Configure the plugin as per your requirements. Here, you need to set “Throttle Matrix Project” to the desired value (typically 1) and select the “Category” option as “Branch Name”.
  5. Save the job configuration.

With this configuration, Jenkins will allow only one build of a specific branch to run at a time, while still allowing other builds of different branches to run concurrently.

Thanks @poddingue and @halkeye , i tried lock within the pipeline and it works great. We will try the “Throttle Concurrent Builds” plugin in the near future. Thanks for the help.

1 Like