How can I prevent two Jenkins projects/builds from running concurrently?
The Locks and Latches plugin should resolve your problem. Create a lock and have both jobs use the same lock. That will prevent the jobs from running concurrently.
- Install the plugin in "Manage Jenkins: Manage Plugins."
- Define (provide a name for) your lock(s) in "Manage Jenkins: Configure System."
- For each job you want to participate in the exclusion,
- in ": Configure: Build Environment," check "Locks",
- and pick your lock name from the drop list.
The Lockable Resources Plugin. Simple and working well for me May 2016.
Install the plugin.
In Manage Jenkins > Configure System go to Lockable Resources Manager.
Select Add Lockable Resource.
Enter values for field: Name and hit Save.
Warning: Do not enter spaces in Name field.
In Jenkins > job_name > Configure > General, Select checkbox: This build requires lockable resources. Enter name or names in value for field: Resources.
Start a build. Under build #number select Locked Resources. You should see something like:This build has locked the following resources: resource_name - resource_description.
Start a different build which uses the same resource. You will see Build Queue in Jenkins status/menu showing job name. Hover text shows Started by, Waiting for resources resources_list, Waiting for time.
(also resource tags/labels can be used)
Adding screenshot of Job Configuration page as there seems to be a problem for some users where "This build requires lockable resources" is not visible: ** when the checkbox is not selected you should only see "[_] This build requires lockable resources"
1 December 2021
Use Build Blocker plugin, Install from Manage Jenkins > Plugin Manager
For example, you have two pipelines React-build and React-tests:
Go to React-build -> Configure -> Block build
if I don't need React-tests
to run concurrently with the current React-build
job, add it in the blocking list,
Regex expressions can also be used, i.e. to avoid concurrent builds for all projects starting with React-
, add React-.*
to the list,
Replace React-tests with any pipeline-name you want not to run parallel, with global or node level options,
When tried to run any blocked jobs together with configured React-build
job, it gets moved to pending state,
EDIT: Below information is effective as of 04/10/2014
Exclusion plugin, https://wiki.jenkins-ci.org/display/JENKINS/Exclusion-Plugin Very useful if few build use the same resource - e.g. a test database. All you need to do is to update configuration of all jobs using this resource and as a result they will never run in parallel but wait for others to complete.
Taken from : http://www.kaczanowscy.pl/tomek/2012-07/jenkins-plugins-part-iii-towards-continuous-delivery
This plugin does block two or more jobs from running in parallel.
To test, do this for job1
- Configure
- Under Build Environment check "Add resource to manage exclusion."
- Then Add -> New Resource -> Name -> lock
- Under Build -> Add build step
- Critical Block Start
- Add build step -> Add whatever you want to add.(add sleep 15 to make sure it lasts longer to check concurrency.)
- Add build step -> Critical block end
- Repeat the above steps for job2, make sure you use the same lock name 'lock'.
- manually build both jobs concurrently.
- Monitor the run progress under jenkins -> Exclusion administration.