Skip to content

Instantly share code, notes, and snippets.

@johnl
Last active January 3, 2018 12:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnl/09fc6b8f48db064f9aea7bb485082d32 to your computer and use it in GitHub Desktop.
Save johnl/09fc6b8f48db064f9aea7bb485082d32 to your computer and use it in GitHub Desktop.
jenkins docker-node-maintenance pipeline job
@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