Comments (6)
@f-steff I think you confused resources and labels. A resource is always the one thing that is locked, it exists once and has an unique name (if we take the hardware example, this may be office_printer_14
). Every resource can have multiple labels (the printer could be labeled dot-matrix-printer
, in-office-printer
, a4-printer
, etc.). All resources with the same label form a "pool", so if you try to lock 1x a4-printer
, you might get a random resource which has the label a4-printer
- if all resources with the label a4-printer
are in use, your job waits until one is available.
from lockable-resources-plugin.
Hi, looking at this today for my setup - it seems that when the Lockable Resources plugin sees a queued job with enabled groovy script, it calls the script for each single definition of a lockable resource, independently. It is up to your script to match the strings in resourceName
and resourceLabel
, maybe resourceDescription
too.
The groovy script ultimately returns true
or false
, so the plugin has an array of accepted resourceName's - and then picks one (assuming you've required "1" as the amount in settings) to lock and return into the build environment in the variable name you've set up for the job. If none of the picked resources are currently available, the job stays in queue and the loop repeats after a few seconds.
Thanks to your write-up, as well as https://github.com/jenkinsci/lockable-resources-plugin/blob/master/src/main/resources/org/jenkins/plugins/lockableresources/RequiredResourcesProperty/help-resourceMatchScript.html for helping figure this out. The println
routine and jenkins.log
were also very helpful ;)
Now, one more quest for me remains - I want this logic to interact with build arguments of the queued job, and those seem to not be available in the context of this groovy script :( UPDATE: Hopefully PR #72 will address this issue of mine.
from lockable-resources-plugin.
Hi @jimklimov,
Thank you for your investigations and findings. Not least the comments on issue #73 which seems really interesting.
I'll see if I can find time to work in it this week, and if successful will update the Jenkins Wiki with simple examples.
If you have discovered more valuable info, please let me know.
Thanks.
from lockable-resources-plugin.
@jimklimov
To access the build-parameters passed to the job, you can use:
import hudson.model.*
def JobParameter = System.getenv("YOUR_PARAMETER_PASSED_TO_THE_SCRIPT")
I tested your hypothesis, by dumping all variables available to the Groovy script:
println "Lockable Resource Groovy Script Start"
this.binding.variables.each {k,v -> println "$k = $v"}
println "Lockable Resource Groovy Script End"
println ""
return false
This resulted in the following output repeated over and over when the job attempted to start:
Lockable Lockable Resource Groovy Script Start
resourceLabels = [Node2A, Node2B, Node2C]
resourceDescription = This is a TEST resource.
resourceName = Node2
Lockable Resource Groovy Script EndLockable Lockable Resource Groovy Script Start
resourceLabels = [Node1A, Node1B, Node1C]
resourceDescription = This is a TEST resource.
resourceName = Node1
Lockable Resource Groovy Script End
So it's possible to match resourceName
and resourceLabels
, and it's possible to return true
or false
.
If true
is returned, all Names and Labels are locked - unless the Number of resources to request value is not a positive number, in which case the job runs without checking the resources.
So effectively it's possible to use this as a simple semaphore, based on the resourceName
, since using resourceLabels
doesn't add any value.
It would be nice if it was possible to return true/false to select on the resourceName
level or a resourceLabels
list to specify the labels this jobs selected to have locked.
from lockable-resources-plugin.
Note that by now my PR is merged. When I was doing similar experiments, I did not see build args as envvars in the evaluated lockable-resources groovy script. It is also quite possible I botched the experiment somehow, not being proficient in Java ;) But I did find "teh codez" on the net to print out all envvars seen by the script's context - and build args were not there for me.
I am not sure I got all your further elaboration about resource matching, but note that locking regards each individual resourceName which often marks some limited (and unshareable) physical resource. It is quite valid for different instances to have same labels (maybe part of different larger label sets) so you can declare "give me any one of these, exclusively while this job runs"!
from lockable-resources-plugin.
Hi again @jimklimov, Sorry for my late delay.
It's great that your PR is merged, but I wonder when it will be released in the plugin?
About my further elaborations, it was based on my understanding of the plugin, which again was based on the old online (and in plugin) help text. As far as I remember, it stated that one resource (name) could have several "sub-resources" (labels), and that you could choose to lock on the all (name), or a few specific, leaving the others available for other jobs.
To me it made sense like this:
Resource name: Transmitters
Resource labels: Transmitter1, Transmitter2, Transmitter3, Transmitter4
#of resources requested: n
So with the above setup, I could have two ways to lock resources.
-
Specify "Transmitters" as Resource name: I would end up getting the amount requested (n), out of the four available transmitters in the pool. If I requested 2, another job could get the other two.
-
Specify the labels to get some specific resources out of the pool.
As I understand the implementation as is is now, the usage of name's or label's doesn't make any difference - as it locks the same resource. And I even less understand the usage of the the amount of resources to lock... - dont you always get all of them?
from lockable-resources-plugin.
Related Issues (20)
- Slash in name breaks navigation in lockable resource view for labels HOT 3
- Option to randomly assign a resource when requested by label HOT 2
- Ability to lock one resource from list, not by label HOT 2
- Re-define ephemeral resources used by revived builds when Jenkins controller is restarted HOT 1
- Aquire lock without using try-with-resources notation HOT 4
- Print detailed lock cause in the build log
- Name and value of properties are missing on api HOT 2
- ConcurrentModificationException when serializing LockedResourcesBuildAction#lockedResources HOT 5
- get lock by resource name result in NPE HOT 3
- Deadlock on Jenkins controller while using lockable resources HOT 13
- it.getQueue() in /lockable-resources/. Reason: java.lang.NullPointerException HOT 7
- Trim spaces from resource name, otherwise it will stuck HOT 1
- Throw excpetion when count of requiered resources is bigger then current count of resources HOT 1
- Unqueue all items contains the build, when the build has been canceled / killed (to improve performance) HOT 1
- Use of [] for extra to not lock is not working anymore with 1232.v512d6c434eb_d release HOT 7
- LRM lacks a method to remove a lockable resource from the list HOT 3
- Empty ressource is not allowed anymore HOT 11
- Lease Time HOT 1
- jenkins startup failure HOT 22
- Is there any API documentation on what is supported? Can this be used from command line outside of jenkins? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lockable-resources-plugin.