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

Mixing direct/inverse precedence locks doesn't yield the expected result

Open giannello opened this issue 7 years ago • 2 comments

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.

giannello avatar Jun 22 '17 13:06 giannello

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 a priority field (defaults to 100) so that locks are acquired in order of priority.

giorgiosironi avatar Oct 02 '17 12:10 giorgiosironi

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")
                          }
                    }
                }
            }
        }
    }
}

lchenay avatar Mar 03 '22 10:03 lchenay