Extended global-shared-library for lockable-resources-plugin #445
mPokornyETM
started this conversation in
Ideas
Replies: 2 comments
-
Hello, I think this is a good idea. Actually, since I did not find out how to use groovy expressions to match labels, I wrote a groovy code that does the matching first by creating a selection (subset) of resources answering the input constraints, then I loop over the resources until I can successfully lock one. It looks like this (I don't handle coffee machines in my real code, that's an example 😉 ): // We can also load these metadata from Yaml or JSON files from a resources folder
def coffee_machines = [
"columbian-strong": [
"origin": "Columbia",
"intensity": 5
],
"ethiopian-middle": [
"origin": "Ethiopia",
"intensity": 3
],
"columbian-light": [
"origin": "Columbia",
"intensity": 2
],
"columbian-middle": [
"origin": "Columbia",
"intensity": 3
]
]
// Custom groovy-based selection
def selection = coffee_machines.findAll { (it.value.origin == "Columbia") && (it.value.intensity < 4) }
if (selection.size() == 0) {
error ("Unable to find a coffee machine with your constraints.")
}
echo ("Found this selection of machines: " + (selection.keySet() as String[]).join(', '))
// Now, let's try to lock one of them
def done = false
selection.each {
if (!done) {
lock (resource: it.key, quantity: 1, variable: 'COFFEE_MACHINE_NAME', skipIfLocked: true) {
done = true
echo "The machine ${COFFEE_MACHINE_NAME} has been reserved for use."
// Prepare the coffee here!
}
}
}
if (!done) {
error ("Sorry, no machine was available. Try again later.")
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
I try to start with the idea |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
There are many of Jenkins-instances used this plugin. A lot of them use this plugin in shared-libraries in a uncommon way and a lot of them make some useful magic.
I will provide shared library which extend lockable-resources-plugin.
There are many things, their can be done in groovy. This can be done also as examples here, but everybody need to copy it into own shared libraries and produce many of duplicated codes around the world. Therefore a library with useful good documented and tested code will be fine.
But to make it fit with Jenkins versions, dependency changes and many amazing things done by plugin development kit will be a challenge. Therefore I am thinking about 'new' plugin.
Pro:
Contra:
Any ideas, examples and contributions are welcome.
Beta Was this translation helpful? Give feedback.
All reactions