Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to make jobs in Jenkins mutually exclusive?

Tags:

mutex

jenkins

I have a few jobs in Jenkins that use Selenium to modify a database through a website's front end. If some of these jobs run at the same time, errors due to dirty reads can result. Is there a way to force certain jobs in Jenkins to be unable to run at the same time? I would prefer not to have to place or pick up a lock on the database, which could be read or modified by any number of users who are also testing.

like image 781
wanderso Avatar asked Sep 13 '11 17:09

wanderso


People also ask

How can you prevent two Jenkins from running in parallel?

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."

Can Jenkins run multiple jobs simultaneously?

Yes it's possible. Doc: If this option is checked, Jenkins will schedule and execute multiple builds concurrently (provided that you have sufficient executors and incoming build requests.)

Can Jenkins Execute jobs in parallel?

In Jenkins, there are several ways to implement parallel job execution. One of the common approaches is the parent-child build model. In this model – a parent (upstream) job is triggering child (downstream) jobs.

Can a single Jenkin job run on multiple nodes?

You can now launch all a job on all nodes.


2 Answers

You want the Throttle Concurrent Builds plugin which lets you define global and per-node semaphores.

Locks and latches is being deprecated in favor of Throttle Concurrent builds.

like image 53
recampbell Avatar answered Sep 20 '22 19:09

recampbell


I've tried both the locks & latches plugin and the port allocator plugin as ways to achieve what you're trying to do. Neither worked reliably for me. Locks & latches worked some of the time, but I'd occasionally get hung jobs. Using port allocator as a hack will work unless you have multiple jenkins nodes, but the config overhead is kind of high. What I've ultimately settled upon is another hack, but it works reliably and uses core Jenkins stuff (no plugins):

  • create a slave node running on the same box as the master (or not, if you have lots of boxes)
  • give this slave a single executor (key)
  • tie the 2 (or n) jobs that must not run together to this new slave node
  • optionally set the slave's usage to 'tied jobs only' if it'll screw up your other jobs if they happen to run on the new slave

Since the slave has only one executor, the jobs tied to it can never run together.

like image 23
overthink Avatar answered Sep 21 '22 19:09

overthink