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?
How can we enable concurrent builds but only if the builds are on different branches?
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.
Hi @srirammk and welcome to this community
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:
- Install the “Throttle Concurrent Builds” plugin on your Jenkins instance.
- Go to the configuration page of the job for which you want to enable concurrent builds.
- Under the “Build Environment” section, check the “Throttle Concurrent Builds” checkbox.
- 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”.
- 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.