-
New Feature
-
Resolution: Unresolved
-
Major
-
None
I found some requests to add a timeout to the plugin, or a number of tries.
My proposal is simpler: add a nowait option
This option would try to acquire the lock only once, enter the closure code if it could successfully lock the resource and throw an exception if it couldn't.
We actually use the lockable-resource plugin with "virtual ressources" to check concurrent access to some environment by different jobs. We dont want to wait for the resource to be free, i strongly believe that this behaviour may also be wanted with real resources (easy to implement a loop for retries and fallbacks with a nowait option).
We actually use an ugly workaround like
stage("Check concurrent environment access") {
try {
timeout(time: 3, unit: 'SECONDS') {
lock("${EnvName}-${EnvNumber}") {}
}
} catch (Exception e) {
error("Another job on this environment is already in progress: " + e)
}
println "No concurrent access detected, executing job..."
}
// Lock environment resource
lock("${EnvName}-${EnvNumber}") {
closure()
}
Which is not safe, we would prefer to use something like
try {
lock("${EnvName}-${EnvNumber}", nowait=true) {
closure()
}
} catch (LockedResource e) {
error("Another job on this environment is already in progress: " + e)
}
- is related to
-
JENKINS-41699 Add a timeout field
- Open
-
JENKINS-61502 Option to (abort,mark unstable, queue) if resouce(s) are unavailable.
- Open