Jenkins – How to prevent two Jenkins projects/builds from running concurrently

hudsonJenkins

I have two Jenkins projects that share a database. They must not be run simultaneously. Strictly speaking, there is no particular dependency between them beyond non concurrency, but at the moment I partially manage this constraint by running one "downstream" of the other. This works most of the time, but not always. If a source control change happens while the second is running, the first will start up again, and they'll be running concurrently and probably both fail miserably.

This is similar, but not identical, to How to prevent certain Jenkins jobs from running simultaneously? The difference is that I don't have a "number of threads" problem — I'm already only running at most one thread of any given project at any one time, even in the case where two (different-project) builds stomp each other. This seems to rule out all the several suggestions in that thread.

Best Answer

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.

  1. Install the plugin in "Manage Jenkins: Manage Plugins."
  2. Define (provide a name for) your lock(s) in "Manage Jenkins: Configure System."
  3. For each job you want to participate in the exclusion,
    1. in ": Configure: Build Environment," check "Locks",
    2. and pick your lock name from the drop list.
Related Topic