jenkinsci / lockable-resources-plugin

Lock resources against concurrent use
https://plugins.jenkins.io/lockable-resources
MIT License
87 stars 182 forks source link

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

Open XavierRaynaud opened 4 years ago

XavierRaynaud commented 4 years ago

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

tomasbjerre commented 4 years ago

Implemented in #185

jimklimov commented 2 years ago

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.

mPokornyETM commented 1 year ago

Note for developer. Document how to unlock resource via LRM. Add there a notice that is potential risk. Maybe we shall add it also in groovy shared lib.