简体   繁体   中英

Create persistent lock dynamically in Jenkins scripted pipeline

In my scripted pipeline I want to create a lock that will persists in the global Jenkins configuration, after the pipeline has finished. I tried the following to no avail.

import org.jenkins.plugins.lockableresources.LockableResourcesManager as LRM
lrm = LRM.get()
lrm.createResource("my_lock")
lrm.save()

The lockable resource is ephemeral: It is created and can be used, but it does not persist. I am on Jenkins 2.226 running the Lockable Resources plugin 2.7.

Your code should look like this:

import org.jenkins.plugins.lockableresources.LockableResourcesManager as LRM
lrm = LRM.get()
lrm.createResource("my_lock")
// Get lockable resource by name
def lockableResource = lrm.fromName("my_lock")
// Make resource permanent (Resources are ephemeral by default)
lockableResource.setEphemeral(false)
lrm.save()

Lockable resources are ephemeral by default. To override it, use method setEphemeral(boolean) .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM