Last active
September 3, 2022 10:49
-
-
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
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
| /** | |
| * @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