Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-46235

API does not allow to remove lockable resource

      There is a way to dynamically create lockable resource within the jenkins pipeline script using LockableResourcesManager::createResource() and ::createResourceWithLabel(), but there are no API method to remove said resource.

      NOTE: Fixing JENKINS-38906 in a way suggested by eeaston could require said method to be developed (as 'transient' resources will be created and removed in pipeline step).

          [JENKINS-46235] API does not allow to remove lockable resource

          Travis Pavek added a comment -

          As a workaround, there is a removeAll option that you can say something like remove all resources where name matches 'somestr'.  For example this is what I do:

           

          def all_lockable_resources = GlobalConfiguration.all().get(org.jenkins.plugins.lockableresources.LockableResourcesManager.class).resources
          
          all_lockable_resources.removeAll { it.name.contains('somestr')}
          

          I use a timestamp in my names and match off that.

          Travis Pavek added a comment - As a workaround, there is a removeAll option that you can say something like remove all resources where name matches 'somestr'.  For example this is what I do:   def all_lockable_resources = GlobalConfiguration.all().get(org.jenkins.plugins.lockableresources.LockableResourcesManager.class).resources all_lockable_resources.removeAll { it.name.contains( 'somestr' )} I use a timestamp in my names and match off that.

          As I try to understand the usecase here (and the blatant violation of script security ): Is the introduction of "ephemeral" resources covering your use cases or do you need something more complex? If you need something more complex, maybe a new set of pipeline steps with proper permission checks is the better way? The LockableResourcesManager API was never designed for use in pipeline...

          (As always, pull requests welcome, but I suspect such a feature could even be its own plugin "extending" the lockable-resources plugin)

          Tobias Gruetzmacher added a comment - As I try to understand the usecase here (and the blatant violation of script security ): Is the introduction of "ephemeral" resources covering your use cases or do you need something more complex? If you need something more complex, maybe a new set of pipeline steps with proper permission checks is the better way? The LockableResourcesManager API was never designed for use in pipeline... (As always, pull requests welcome, but I suspect such a feature could even be its own plugin "extending" the lockable-resources plugin)

            Unassigned Unassigned
            mireksz Mirek Sz
            Votes:
            3 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated: