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

Lock when required

Open jshthornton opened this issue 10 years ago • 5 comments

It would be an great feature to be able to specify in the build task list when to lock / unlock resources. Say for example I have a build that takes 30 minutes to execute, but the locked resource in only in used during 3 minutes of that build (especially at the end of the build).

It would allow for a configuration such as this:

  • Task A (27 mins)
  • Lock Resource: X
  • Task B (3 mins)

This will allow multiple long builds to do a lot of their grunt work up until such a time where they need to await the unlock of a resource.

jshthornton avatar Jun 29 '15 07:06 jshthornton

I think what you're requesting would be to have resource lock/unlock as build steps. Would that allow you to implement your jobs in the desired fashion?

Please note I am NOT a developer of this plugin, I am just trying to help you clarify this request. On the other hand, I think the plugin authors don't pay much attention to issues on Github, but only to issues in Jira.

eddyp avatar Aug 18 '15 22:08 eddyp

I'd use a multiphase job type, or a freestyle step calling other subjobs (and waiting for results) - and locking the resource for its 3 minutes of fame in that subjob.

Would this approach solve your issue? Did you come up with something better over the two years? :)

jimklimov avatar Nov 14 '17 20:11 jimklimov

In a declarative pipeline, you can lock a single stage:

pipeline {
    agent any
    stages {
        stage('Task A') {
            steps {
                echo 'do sth for 27min'
                echo 'foo is not locked'
            }
        }
        stage('Task B') {
            options {
                lock(label: 'foo', quantity: 1)
            }
            steps {
                echo 'do sth for 3min'
                echo 'foo is locked'
            }
        }
        stage('Task C') {
            steps {
                echo 'do sth else'
                echo 'foo is not locked anymore'
            }
        }
    }
}

If you need to lock sth for more than one stage, you can group them in a stages block:

pipeline {
    agent any
    stages {
        stage('Task A') {
            steps {
                echo 'do sth for 27min'
                echo 'foo is not locked'
            }
        }
        stage('Lock foo') {
            options {
                lock(label: 'foo', quantity: 1)
            }
            stages {
                stage('Task B') {
                    steps {
                        echo 'do sth for 3min'
                        echo 'foo is locked'
                    }
                }
                stage('Task C') {
                    steps {
                        echo 'do sth else'
                        echo 'foo is still locked'
                    }
                }
            }
        }
        stage('Task D') {
            steps {
                echo 'do sth else'
                echo 'foo is not locked anymore'
            }
        }
    }
}

clonejo avatar Jul 22 '19 13:07 clonejo

Declarative or scripted Pipelines are more powerful and the 'old fashion' free style projects dies slowly. Therefore I think no body will invest time for this issue. When everybody is fine with them, I will close this issue. Thx

mPokornyETM avatar Oct 17 '22 22:10 mPokornyETM

Maybe after moving the idea to docs... but yeah.

jimklimov avatar Oct 18 '22 07:10 jimklimov