Hi friend i have 2 lockable resource while executing same job 2 times i want 2nd job will move 2nd lcokable resource how can i do it

157 views
Skip to first unread message

Satya Muralidhar Peddireddi

unread,
Apr 30, 2020, 4:37:41 AM4/30/20
to Jenkins Users
pipeline {
    agent any
    stages {
        stage('sample_1') {
            steps { 
                script {
                    if(true) {
                        lock(label: 'Resource1') {
                            sh label: '', script: 'echo $JAVA_HOME'
                            sleep time: 1, unit: 'MINUTES'
                        }   
                    } 
                    else{
                        lock(label: 'Resource2') { 
                            sh label: '', script: 'echo $JAVA_HOME'
                            sleep time: 1, unit: 'MINUTES'
                        }
                    }
                }
            }
        }
    }
}


Gianluca

unread,
Apr 30, 2020, 4:54:00 AM4/30/20
to Jenkins Users

It's not really clear what you want ... but nevertheless I think you have got the solution.
You have an "if" ... you just need to figure it out what is the condition that makes you go to the else branch.

So, why one job should lock "Resource 1" and another should "Resource 2"?

Satya Muralidhar Peddireddi

unread,
Apr 30, 2020, 9:46:28 AM4/30/20
to jenkins...@googlegroups.com
It's my test case I want run same job parallely in different locks.if one lock is busy go to another lock

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/56d4aaa9-5435-4a18-ac5a-a4659222538e%40googlegroups.com.

Christoph Fetzer

unread,
Apr 30, 2020, 10:27:52 AM4/30/20
to Jenkins Users
Don't you actually want to use a ressource pool with two locks which use the same label?


Am Donnerstag, 30. April 2020 15:46:28 UTC+2 schrieb Satya Muralidhar Peddireddi:
It's my test case I want run same job parallely in different locks.if one lock is busy go to another lock

On Thu, Apr 30, 2020, 14:24 Gianluca <gma...@gmail.com> wrote:

It's not really clear what you want ... but nevertheless I think you have got the solution.
You have an "if" ... you just need to figure it out what is the condition that makes you go to the else branch.

So, why one job should lock "Resource 1" and another should "Resource 2"?


On Thursday, 30 April 2020 09:37:41 UTC+1, Satya Muralidhar Peddireddi wrote:
pipeline {
    agent any
    stages {
        stage('sample_1') {
            steps { 
                script {
                    if(true) {
                        lock(label: 'Resource1') {
                            sh label: '', script: 'echo $JAVA_HOME'
                            sleep time: 1, unit: 'MINUTES'
                        }   
                    } 
                    else{
                        lock(label: 'Resource2') { 
                            sh label: '', script: 'echo $JAVA_HOME'
                            sleep time: 1, unit: 'MINUTES'
                        }
                    }
                }
            }
        }
    }
}


--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkins...@googlegroups.com.

Stuart Rowe

unread,
May 1, 2020, 6:58:55 PM5/1/20
to Jenkins Users
I agree with Christoph that there are better approaches. However, if you really want to do this you can use the new skipIfLocked feature added in lockable-resource 2.8:
pipeline {
   agent any
   stages {
       stage('sample_1') {
           steps {
                script {
                   def lockedResource1 = false
                   lock(label: 'Resource1', skipIfLocked: true) {
                       lockedResource1  = true
                        sh label: '', script: 'echo $JAVA_HOME'
                       sleep time: 1, unit: 'MINUTES'
                   }
                    if (!lockedResource1)

Satya Muralidhar Peddireddi

unread,
May 2, 2020, 12:40:40 AM5/2/20
to jenkins...@googlegroups.com
i tried this script still its waiting for another lock
pipeline {
   agent any
   stages {
       stage('sample_1') {
           steps {
                script {
                   def lockedResource1 = false
                   lock(label: 'Resource1', skipIfLocked: true) {
                       lockedResource1  = true
                        sh label: '', script: 'echo $JAVA_HOME'
                       sleep time: 1, unit: 'MINUTES'
                   }
                    if (!lockedResource1)
                       lock(label: 'Resource2') {
                            sh label: '', script: 'echo $JAVA_HOME'
                           sleep time: 1, unit: 'MINUTES'
                       }
                   //}
               }
           }
       }
   }
}

To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/2129e9ad-9629-41e3-9c92-525705b71295%40googlegroups.com.


--


Regards,

Muralidhar

Stuart Rowe

unread,
May 2, 2020, 1:24:01 AM5/2/20
to Jenkins Users

Satya Muralidhar Peddireddi

unread,
May 2, 2020, 1:27:34 AM5/2/20
to jenkins...@googlegroups.com
Yes. 

On Sat, May 2, 2020, 10:54 Stuart Rowe <stuar...@gmail.com> wrote:
--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.

Stuart Rowe

unread,
May 3, 2020, 1:40:50 PM5/3/20
to Jenkins Users
That's disappointing. Perhaps you can report this issue to the plugin maintainers? That is the use case for the skipIfLocked feature.
Reply all
Reply to author
Forward
0 new messages