lockable-resources-plugin icon indicating copy to clipboard operation
lockable-resources-plugin copied to clipboard

Lock management "by hand": example with early release of a lock

Open XavierRaynaud opened this issue 4 years ago • 3 comments

Hi,

I've a Jenkins job using pipeline and locks. My Jenkinsfile looks like that:

[...]
lock(resource: 'mylock') {
  parallel foo: stuff_for_foo, bar: stuff_for_bar
}
[...]

Of course, the lock is kept until foo and bar are both terminated. I would like to know whether it's possible to release the lock as soon as one there is a failure (in either foo or bar). Note: I'm aware of the "failFast" option of parallel step. However, I do not want to kill all branches in case of failure. Just to release the lock.

Is it possible to lock and release resources directly using API ? Perhaps using LockableResourceManager.lock(..) and LockableResourceManager.freeResources(...) programmatically ?

Any clue on this topic ?

Many thanks

XavierRaynaud avatar Nov 14 '19 17:11 XavierRaynaud

Implemented in #185

tomasbjerre avatar Feb 17 '20 18:02 tomasbjerre

Just reading the original issue, I am trying to understand how the use-case fits with lockable resource concepts? If the resource represented a device, or some other token for dedicated use by some one consumer at a time, doesn't the surviving branch of your parallel job still need it (and need that someone else does not hijack it)? Otherwise, could there be separate resources for those separate branches?

Otherwise, as good an example as any for the optionally separated locking and unlocking activities.

jimklimov avatar Feb 06 '22 15:02 jimklimov