Last active
January 3, 2018 12:42
-
-
Save johnl/09fc6b8f48db064f9aea7bb485082d32 to your computer and use it in GitHub Desktop.
jenkins docker-node-maintenance pipeline job
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@NonCPS | |
List <String> getOnlineNodeNames() { | |
List <String> nodeNames = [] | |
for (node in Jenkins.getInstance().getNodes()) { | |
if (node.getComputer().isOnline()) { | |
nodeNames.add(node.name.toString()) | |
} | |
} | |
return nodeNames | |
} | |
// The script triggers PayloadJob on every node. | |
// It uses Node and Label Parameter plugin to pass the job name to the payload job. | |
// The code will require approval of several Jenkins classes in the Script Security mode | |
def branches = [:] | |
for (nodeName in getOnlineNodeNames()) { | |
// Into each branch we put the pipeline code we want to execute | |
branches["node_" + nodeName] = { | |
node("master") { | |
echo "Triggering on " + nodeName | |
build job: 'Maintenance/docker-node-maintenance', parameters: [ | |
new org.jvnet.jenkins.plugins.nodelabelparameter.NodeParameterValue | |
("TARGET_NODE", "description", nodeName) | |
] | |
} | |
} | |
} | |
// Now we trigger all branches | |
parallel branches |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment