'Lockable Resources' within Jenkins global configuration can grow quickly when lock names are selected which are dynamically created and are transient in nature.
Would be nice to clean-up the global configuration when locks released by removing the named lock value.
Removing on release would not be safe. +1 for the transient parameter.
There should be a periodic background task looping on defined resources and removing those marked as transient and not used after a specific amount of time.
Also transient resources should not be displayed in the administration page as it does not make sense to configure them nor remove them.
Javier Delgado any luck getting that script to work as a jenkins job? I keep getting odd errors when trying to run it as a script. I can run it the script console but not as a regular job in the "Build" section.
David Taylor, that script has been working as a pipeline job since 10/17, on several Jenkins instances and versions. Wont the "odd errors" related to metrods needed to become approved via the instance scriptApproval service?
Bump - curious if anything can be done about this. Not having the ability to clean up locks that are auto-created seems like more than a "minor" priority... this could quickly balloon out of control.
Aaron Marasco You should synchronize access to LocalbleResouceManager, otherwise you might cause race condition. Considering LocakbleResourcesManager relies on synchronization, it should actually be a trivial task to delete lock after it has been released.
Edit: I had time to study problem further. While this does resolve race condition when deleting item from list, it still isn't sufficient. Current lock allocation algorithm relies that locks are not deleted in any way. I think that's something I can fix. However I think that algorithm needs major rework. Everything related lock management has to be done with atomic operations - and to do so, management must be done in a single class. There might be some scalability issues when allocating hundreds of locks, that could be resolved as well.{code}
We're using this to delete locks after our ansible plays: {code:java} @NonCPS def deleteLocks(lockNames) { def manager = org.jenkins.plugins.lockableresources.LockableResourcesManager.get() synchronized (manager) { manager.getResources().removeAll { r -> lockNames.contains(r.name) && !r.locked && !r.reserved } manager.save() } }
{code}
Edit: I had time to study problem further. While this does resolve race condition when deleting item from list, it still isn't sufficient. Current lock allocation algorithm relies that locks are not deleted in any way. I think that's something I can fix. However I think that algorithm needs major rework. Everything related lock management has to be done with atomic operations - and to do so, management must be done in a single class. There might be some scalability issues when allocating hundreds of locks, that could be resolved as well.{code}
Using code from comments above, I have a Jenkins job that runs weekly to remove the ones that start with certain phrases. *This may have race conditions* (see later comments): {code:java}
Thanks Sami Korhonen for the heads-up. I don't need to worry about race conditions in my unique situation. However, I'll make a note in case others just see it and copypasta.