// Branches for parallel node runs
def branches = [:]// Nodes. In real setup this would only contain nodes that are online at the time the pipeline runsdef node_names = ["A", "B"]// Short sleep time of 15 seconds. Later, it'll get reduced to 5 if the node name is Bdef sleep_time = 15
// Loop through the nodes and create the data in the branch list to run in parallel on at the endnode_names.each { node_name -> println node_name
branches["node_" + node_name] = { // Doing something like this doesn't do anything //if (!isNodeOnline(node_name)) { // println "node name " + node_name + " is offline, returning" // return //}
node(node_name) { // If the node that is being looked at is B then set the sleep time to 5 so that it runs // a shorter time than A. Later, it's hardcoded to fail B and take it offline. This way // A stays in the queue running and B is done and offline. def temp_sleep_time = sleep_time if (node_name == "B") { temp_sleep_time = 5 }
timestamps { stage("pre-build") { println "Prebuilding " + node_name + "!" sleep time: temp_sleep_time, unit: 'SECONDS' println "Done with pre-build!" } stage("build") { println "Building " + node_name + "!" sleep time: temp_sleep_time, unit: 'SECONDS' println "Done with build!" } stage("post-build") { println "Post building " + node_name + "!" if (node_name == "B") { println "Taking node offline and failing build!" takeNodeOffline("Derp", "B") currentBuild.result = "FAILED" done = true return } sleep time: temp_sleep_time, unit: 'SECONDS' println "Done with post-build!" } } } }}parallel branchesWanted to expand and sort of answer the questions I asked here.