-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create a Groovy script to apply singleton labels. #917
Conversation
I think this script will need to be run as a system groovy script rather than with the sandbox. I have successfully tested it using the Jenkins script console.
if (label_nodes.size() == 1) { | ||
println(tup[0] + " is currently applied to " + label_nodes[0].name) | ||
continue | ||
} | ||
|
||
if (label_nodes.size() > 1) { | ||
println("WARNING: Too many nodes with the label " + tup[0]) | ||
for (node in label_nodes) { | ||
println(" " + node.name) | ||
} | ||
continue | ||
} | ||
|
||
if (label_nodes.size() < 1) { | ||
println("No host currently has the label " + tup[0]) | ||
println("Appointing a node from the configured pool matching '" + tup[1] + "'") | ||
node_set = Label.get(tup[1]).getNodes() | ||
if (node_set.size() <= 0) { | ||
println("WARNING: Pool of '" + tup[1] + "' machines for " + tup[0] + " is empty!") | ||
} | ||
node_pool = [] | ||
for (node in node_set) { | ||
node_pool.add(node) | ||
} | ||
Collections.shuffle(node_pool) | ||
appointed_node = node_pool[0] | ||
new_label_string = appointed_node.getAssignedLabels().join(" ") | ||
new_label_string = tup[0] + " " + new_label_string | ||
appointed_node.setLabelString(new_label_string) | ||
appointed_node.save() | ||
println("Added label to " + appointed_node.name) | ||
continue | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ended up using if
and continue
since Groovy has no internal elseif and I find the compound flow control spacing hard to read. However, if (hehe) there is a preference for if (...) {...} else if (...) {...}
I am open to changing it.
I'd like to make this a struct/class but I'm not quite sure yet.
I was bending around the immutable set in order to use shuffle. But this is much shorter and makes me happier.
Signed-off-by: Jose Luis Rivero <[email protected]>
Signed-off-by: Jose Luis Rivero <[email protected]>
Signed-off-by: Jose Luis Rivero <[email protected]>
Signed-off-by: Jose Luis Rivero <[email protected]>
Some changes to the PR:
Still need to push some changes and run the testing. Move to draft by now. Hope to finish it by the end of today. |
Signed-off-by: Jose Luis Rivero <[email protected]>
Signed-off-by: Jose Luis Rivero <[email protected]>
Signed-off-by: Jose Luis Rivero <[email protected]>
Thanks for the assistance @j-rivero! Those changes are all very welcome! |
* Create a Groovy script to apply singleton labels. I think this script will need to be run as a system groovy script rather than with the sandbox. I have successfully tested it using the Jenkins script console. * Add a comment describing the form. I'd like to make this a struct/class but I'm not quite sure yet. * Replace shuffle with an in-place pick of a random number. I was bending around the immutable set in order to use shuffle. But this is much shorter and makes me happier. * Add a global coment in the file Signed-off-by: Jose Luis Rivero <[email protected]> * Add the _nightly_node_labeler DSL job Signed-off-by: Jose Luis Rivero <[email protected]> * Filter nodes to only online nodes Signed-off-by: Jose Luis Rivero <[email protected]> * Mark build as unstable if labels were not set correctly Signed-off-by: Jose Luis Rivero <[email protected]> * Support for cron operations on nightly preparation Signed-off-by: Jose Luis Rivero <[email protected]> * Mark build unstable for non expected scenarios Signed-off-by: Jose Luis Rivero <[email protected]> * Fix path expected by Jenkins Signed-off-by: Jose Luis Rivero <[email protected]> --------- Signed-off-by: Jose Luis Rivero <[email protected]> Co-authored-by: Jose Luis Rivero <[email protected]>
* Create a Groovy script to apply singleton labels. I think this script will need to be run as a system groovy script rather than with the sandbox. I have successfully tested it using the Jenkins script console. * Add a comment describing the form. I'd like to make this a struct/class but I'm not quite sure yet. * Replace shuffle with an in-place pick of a random number. I was bending around the immutable set in order to use shuffle. But this is much shorter and makes me happier. * Add a global coment in the file Signed-off-by: Jose Luis Rivero <[email protected]> * Add the _nightly_node_labeler DSL job Signed-off-by: Jose Luis Rivero <[email protected]> * Filter nodes to only online nodes Signed-off-by: Jose Luis Rivero <[email protected]> * Mark build as unstable if labels were not set correctly Signed-off-by: Jose Luis Rivero <[email protected]> * Support for cron operations on nightly preparation Signed-off-by: Jose Luis Rivero <[email protected]> * Mark build unstable for non expected scenarios Signed-off-by: Jose Luis Rivero <[email protected]> * Fix path expected by Jenkins Signed-off-by: Jose Luis Rivero <[email protected]> --------- Signed-off-by: Jose Luis Rivero <[email protected]> Co-authored-by: Jose Luis Rivero <[email protected]>
I think this script will need to be run as a system groovy script rather than with the sandbox. I have successfully tested it using the Jenkins script console.
I have not yet created the DSL job for it. I was hoping for some advice on how best to proceed there since storing the script in a standalone file isn't compatible with the system groovy script approach directly. I think what I'll need to do is read the file out of the release-tools git checkout from the Groovy DSL and supply the contents as a string to the system groovy field on the job.