lockable-resources-plugin icon indicating copy to clipboard operation
lockable-resources-plugin copied to clipboard

Added support for advanced label filters when locking

Open gaspardpetit opened this issue 3 years ago • 3 comments

Finding resources based on labels is nice, but the current implementation is very limiting. We would need to be able to filter out some resources.

Typically when implementing filters, my experience is that a trio of all/any/none is sufficient for most use cases, so instead of just adding exclusion I added all three.

  • anyOfLabels will consider resources if they have at least one matching label
  • allOfLabels will consider resources if all labels match
  • noneOfLabels will consider resources unless any of their label matches

The previously used label is still supported and considered a "simple" case of finding a resource using a single label. In implementation, this value is merged into the allOfLabels down the road.

The three new filters are placed under an "Advanced" group in the jelly.

I hope this is useful to others as well. Happy to make any changes necessary to get this PR in.

  • [x] Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • [x] Ensure that the pull request title represents the desired changelog entry
  • [x] Please describe what you did
  • [x] Link to relevant issues in GitHub or Jira
  • [x] Link to relevant pull requests, esp. upstream and downstream changes
  • [x] Ensure you have provided tests - that demonstrates feature works or fixes the issue

gaspardpetit avatar Feb 09 '22 22:02 gaspardpetit

Thanks for the review, I added back the getResourcesWithLabel with deprecation notice. I have been using this change in our production build Jenkins for over a month now and it's working great. In our case, we allow labeling some resources as 'offline' (using https://github.com/jenkinsci/lockable-resources-plugin/pull/305) and then filter on lock(extra:[quantity:1, allOfLabel:'console', noneOfLabel:'offline']). Happy to make any other changes that can get this into the main branch.

gaspardpetit avatar Mar 27 '22 14:03 gaspardpetit

I love this addition ! Any chance to see it merged soon?

chickenkiller avatar Apr 04 '22 13:04 chickenkiller

Any update on this? this feature will be super useful for our use case

DonnieKim411 avatar Jun 27 '22 21:06 DonnieKim411

will be handled in #428

mPokornyETM avatar Dec 08 '22 11:12 mPokornyETM

would this feature also support allocating a resource to a specific node (eg by name reference) , then checking as one of the conditions that such node is online? Eg image 6 nodes each having a printer, for which some printer_NN resource is defined with label 'printer'. How to lock a printer resource from an online node?

monger39 avatar Jan 30 '23 20:01 monger39

would this feature also support allocating a resource to a specific node (eg by name reference) , then checking as one of the conditions that such node is online? Eg image 6 nodes each having a printer, for which some printer_NN resource is defined with label 'printer'. How to lock a printer resource from an online node?

There are few similar PRs and no one is completed (for some historical reason). At the moment it is hard to merge master in this branches. Therefore will be this PR probably closed and handled in #428. To your question about node filters. I have also created #341 which is similar idea. When you need to use some special (more sophisticated) filter just now, you can use a Groovy expression. When it does not match your requirements, please create a new enhancement issue here in GitHub. It will be also helpful to provide a small example, how you want to use it in your pipeline?

PS: Strange for some reason is the Groovy expression visible only in free-style jobs. This shall be fixed. Please help me and create new issue here in GitHub (thx) image

PS2: currently I am thinking about new global-lockable-resources-shared-library which extends core functionality in groovy. Because of historical reason, are many things no more possible here (without big effort, by refactoring this plugin). This can be loaded by you, in your Jenkins instance and used for free. BUT it need time and we shall specified which content shall be done there. Currently nobody will contribute (there)[https://github.com/jenkinsci/lockable-resources-plugin/discussions/445]. Maybe you will find some time and help me (us). It does not mean to contribute on coding. Describe an idea in new issues helps too ;-)

mPokornyETM avatar Jan 30 '23 20:01 mPokornyETM

@mPokornyETM : I have created a new issue https://github.com/jenkinsci/lockable-resources-plugin/issues/455 describing my idea of the use-case. I would be even willing to help on the coding part, but am an absolute newbie on plugin development (and Java ;-) )

monger39 avatar Jan 31 '23 19:01 monger39

@mPokornyETM : I have created a new issue #455 describing my idea of the use-case. I would be even willing to help on the coding part, but am an absolute newbie on plugin development (and Java ;-) )

Any help is welcome. Contributing is not only about Java. Documentation, testing, PR-reviews, bug-management, localizations, bring new ideas and many more. Please join our chat and we can discuss any thing you want ;-) https://gitter.im/jenkinsci/lockable-resources

mPokornyETM avatar Jan 31 '23 22:01 mPokornyETM