user2582961
user2582961

Reputation: 61

Locking multiple external resources in Jenkins

Is it possible to lock multiple external resources to a build in Jenkins? We have tried the External Resource Dispatcher Plugin but did not succeed.

Upvotes: 6

Views: 5759

Answers (3)

Sai Sandeep Golla
Sai Sandeep Golla

Reputation: 11

There is an option called extra to lock on resources in addition to the main resource specified.

lock(extra: [[resource: 'a']], resource: 'b') {
     //code
}

Now any other lock for either 'a' or 'b' will wait for the above lock.

You can find more about it here https://www.jenkins.io/doc/pipeline/steps/lockable-resources/

Upvotes: 1

ceztko
ceztko

Reputation: 15237

It's not clear if your issue can be solved only through the External Resource Dispatcher plugin (which doesn't seem to have strong active development) but if you can afford to use the Lockable Resources Plugin as pointed by chown, there's a simplified syntax to lock multiple named resources in the Jenkins pipelines, as pointed in this support request:

pipeline {
    agent any
    options {
         // Pipeline scoped multiple resource lock
        lock(extra: [[resource: 'resa'], [resource: 'resb']])
    }
    stages {
        stage('Build') {
            steps {
                 // Stage scoped multiple resource lock
                lock(extra: [[resource: 'resc'], [resource: 'resd']])
                {
                    // ...
                }
            }
        }
    }
}

Upvotes: 4

chown
chown

Reputation: 52778

You should also check out the Lockable Resources Plugin:

This plugin allows to define lockable resources (such as printers, phones, computers, etc.) that can be used by builds. If a build requires an resource which is already locked, it will wait for the resource to be free. One can define a lock-priority globally and on a per-job basis.

https://github.com/jenkinsci/lockable-resources-plugin

Upvotes: 1

Related Questions