fhcat
fhcat

Reputation: 1243

How to access the "Lock and Latches" plugin in a Jenkins build flow?

I am using the Jenkins build flow plugin. I have two build flows which I want to prevent running at the same time. I know how to use the "Locks and Latches" plugin to do the same thing for two regular jobs. But for build flows they do not have the Build Environment tab. So how can I use the plugin to lock the two build flows? I don't care if it is done in job configuration or flow DSL.

Upvotes: 2

Views: 1378

Answers (1)

Mike Robinson
Mike Robinson

Reputation: 11

While it doesn't use the Locks and Latches plugin, this seems to do a similar job:

lock(resource: 'myResource', inversePrecedence: true){
  node('job-runner') {
    stage('one at a time') {
      // do a thing
    }
}

By creating a lock, new jobs requiring the same named lock (created by the lock statement) will pause and wait for the lock to be released.

The inversePrecedence: true means that the newest of the jobs waiting for the lock will get it next. You can leave this out if you prefer the jobs run in order. Using milestone() along with inversePrecedence you can get the inbetween jobs to self cancel (in case, say multiple commits to a PR kick off a series of jobs)

source: Controlling the Flow

Upvotes: 1

Related Questions