lockable-resources-plugin
lockable-resources-plugin copied to clipboard
Mixing direct/inverse precedence locks doesn't yield the expected result
We have a jenkins job that uses locks to avoid running a specific stage in parallel even if the job has multiple instances running at the same time.
We normally lock the resource with inversePrecedence: false
to have a FIFO-like behaviour. In some cases, however, we want one specific run to 'jump' over the queue, and that is possible with a build-specific parameter. However, the build that acquires the lock with inversePrecedence: true
is still executed after all the other builds are done.
The LIFO-like behaviour is only respected when all the locks are acquired with inversePrecedence: true
.
It would be great if the plugin could handle this mixed behaviour.
A similar use case is low priority builds:
- you normally run builds with
inversePrecedence: true
- you can sometime specify
inversePrecedence: false
and they go at the back of the queue Although, it seems if we are mixing the LIFO/FIFO model a more flexible feature could be apriority
field (defaults to100
) so that locks are acquired in order of priority.
It doesn't solve the current issue with inversePrecedence doesn't react as expected, but if you want a work around for allowing jumping the queue, here an exemple with a optional lock in front of the real one:
pipeline {
options {
ansiColor('xterm')
timestamps()
}
parameters {
booleanParam(name: 'FASTLANE', defaultValue: false, description: 'Toggle this value for fastlane deployment')
}
stages {
stage('Slowlane? lock') {
options {
lock(extra: (params.FASTLANE ? [[]] : [resource: 'hyperloop-deployment-slowlane']))
}
stages {
stage('Deploy') {
options {
lock(resource: 'hyperloop-deployment')
}
steps {
script {
echo 'Doing the deployment'
sleep(time: 120, unit: "SECONDS")
}
}
}
}
}
}
}