[feat][jenkins] add func for getting list of workers
PRODX-11828
Change-Id: Ieb2c08383eb2b30fdf2da16a290260a7aab2d09b
diff --git a/src/com/mirantis/mk/JenkinsUtils.groovy b/src/com/mirantis/mk/JenkinsUtils.groovy
index a9c5d0c..52eeb62 100644
--- a/src/com/mirantis/mk/JenkinsUtils.groovy
+++ b/src/com/mirantis/mk/JenkinsUtils.groovy
@@ -304,3 +304,28 @@
return meta
}
+
+/**
+ * Get list of all jenkins workers matched desired label
+ *
+ * @param labelString (string) desired worker label
+ * @return (list) all workers, currently matched label
+ */
+@NonCPS
+def getWorkers(String labelString = null) {
+ def workerLabel = hudson.model.labels.LabelAtom.get(labelString)
+ def workers = []
+ hudson.model.Hudson.instance.slaves.each {
+ if (it.getComputer().isOnline()) {
+ if (workerLabel) {
+ if (workerLabel in it.getAssignedLabels()) {
+ workers << it.name
+ }
+ } else {
+ // if labelString is null, getting all workers
+ workers << it.name
+ }
+ }
+ }
+ return workers
+}