LRM lacks a method to remove a lockable resource from the list
Closed this issue · 3 comments
What feature do you want to see added?
I've recently got a stuck ephemeral resource which was not removed from the list of lockable resources, even across several Jenkins restarts (which should involve clean-up). This resource is no longer occupied by any job that it was temporarily made for, just sits stuck there (it may be a contributing factor that the Jenkins instance in question has no persistent resources - could the auto-cleanup leave one resource in the list? it did auto-clean some other resources during restarts...)
Anyway that is a separate problem. As for this one -- as I was trying to gracefully clean the list, using the scripting console, I found that LRM offers many methods about adding, reserving, recycling, etc. but none to remove/destroy/delete a resource. The best I could come up with was using the reference to its internal resources
list which is not too nice of a programming pattern in general (no synchronized
wraps etc. here):
org.jenkins.plugins.lockableresources.LockableResourcesManager lrm = org.jenkins.plugins.lockableresources.LockableResourcesManager.get()
lrm.getResources().removeIf({r -> r.getName() == 'dynamatrix-stash:nut-ci-src:jenkins-nut-nut-PR-2220-1'})
So the proposal is to add a method (or two) that can delete a resource from the list, by LockableResource
type directly or by its String
name, so this is done "properly".
Upstream changes
No response
Are you interested in contributing this feature?
Yes, if others agree this is useful :)
I like it. Something like ?
LRM.removeResource(String resourceName)
LRM.removeResource(LocakbleResource resource)
LRM.removeResourceByLabel(String label)
LRM.removeResourceByLabel(String label, int quantity)
Method LRM.removeResources() has been added, therefore it might be closed.