Skip to content

Instantly share code, notes, and snippets.

@cmaggiulli
Last active September 3, 2022 10:49
Show Gist options
  • Select an option

  • Save cmaggiulli/84fbc17f34fa673cfe9be378949fdee6 to your computer and use it in GitHub Desktop.

Select an option

Save cmaggiulli/84fbc17f34fa673cfe9be378949fdee6 to your computer and use it in GitHub Desktop.
This imperative Jenkinsfile will dynamically create nodes and commands that will be ran in parallel reference impl
/**
* @Author Chris Maggiulli
*
* This is an imperative ( scripted ) Jenkinsfile which will dynamically create nodes and run them in parallel. Modify the List of Hashmaps
* to include the name of the node and the command you wish to run.
*
**/
node('master') {
stage('orchestration') {
dynamicStages = [:]
def nodesCommandList = [ [name:"sqlplus", command:"ls -ltra"], [name:"jdk11", command:"echo hello"] ]
nodesCommandList.each{ nodeCommand ->
/*
* This creates a map of closures that represent a node
* The node closure is the value of the map
* This is used to dynamically create parallel nodes
*/
dynamicStages["${nodeCommand['name']}"] = {
node {
stage("${nodeCommand['name']}") {
sh "${nodeCommand['command']}"
}
}
}
}
parallel dynamicStages
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment