TxAG98
TxAG98

Reputation: 1120

How do I prevent two different Jenkins pipelines from being able to run concurrently?

We have a use case where we have two different Jenkins pipelines, A and B, where A can trigger B and B can trigger A, but we want to be able to constrain A and B so that A can't run if B is still running and vice versa.

I know how one can create a single pipeline and prevent it from running multiple copies of itself, but is there a way we can have a pipeline check the status of another job and block until that other job has finished?

Upvotes: 1

Views: 46

Answers (1)

KeepCalmAndCarryOn
KeepCalmAndCarryOn

Reputation: 9075

It sounds like you need the lockable resource plugin

from its page:

echo 'Starting'
lock('my-resource-name') {
  echo 'Do something here that requires unique access to the resource'
  // any other build will wait until the one locking the resource leaves this block
}
echo 'Finish'

Upvotes: 1

Related Questions