Last active
May 25, 2017 16:41
-
-
Save plukevdh/d5ee63dbed6be37e6b3873a9426977c9 to your computer and use it in GitHub Desktop.
Dynamic Pipeline Flow Example
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
// Example envs, could be one of the following | |
def defaultEnvs = [ | |
[env: "stage", region: "us-east-1"], | |
[env: "prod", region: "us-east-1"] | |
] | |
// Or | |
def defaultEnvs = [ | |
[env: "stage", region: "us-east-1"] | |
] | |
// Or | |
def defaultEnvs = [ | |
[env: "stage", region: "us-east-1"], | |
[env: "prod", region: "us-east-1"], | |
[env: "stage", region: "eu-central-1"], | |
[env: "prod", region: "eu-central-1"] | |
] | |
// Etc... | |
stage("Plan") { | |
def planJobs = [:] | |
for(int i = 0; i < envs.size(); i++) { | |
def details = envs.get(i) | |
planJobs["${details-env}-${details.region}"] = { | |
node() { | |
checkout scm | |
// run things, etc | |
} | |
} | |
} | |
parallel(planJobs) | |
} | |
stage("Apply") { | |
def applyJobs = [:] | |
for(int i = 0; i < envs.size(); i++) { | |
def details = envs.get(i) | |
applyJobs["${details-env}-${details.region}"] = { | |
def apply = false | |
try { | |
confirmedUser = input message: 'Apply Plan?', ok: 'Apply', submitterParameter: 'confirmedUser' | |
apply = true | |
} catch (err) { | |
apply = false | |
currentBuild.result = 'ABORTED' | |
} | |
if(apply) { | |
node() { | |
checkout scm | |
// run things, etc | |
} | |
} | |
} | |
} | |
parallel(applyJobs) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment