Created
December 27, 2016 21:19
-
-
Save gkspranger/0ff20e1d0bcda37a0e75c58b3474ec9e to your computer and use it in GitHub Desktop.
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
def jsonString = readFileFromWorkspace("jobs.json") | |
def slurper = new groovy.json.JsonSlurper() | |
json = slurper.parseText(jsonString) | |
/* example JSON | |
{ | |
"cronJobs":[ | |
{ | |
"name": "Cron_Run_Ansible_Dev", | |
"vars":[ | |
{ "name": "Branch", "value": "develop" }, | |
{ "name": "Inventory", "value": "ec2.py" }, | |
{ "name": "Limit", "value": "tag_env_dev" } | |
], | |
"cron": "20 * * * *", | |
"disabled": false | |
}, | |
{ | |
"name": "Cron_Run_Ansible_Stage", | |
"vars":[ | |
{ "name": "Branch", "value": "develop" }, | |
{ "name": "Inventory", "value": "ec2.py" }, | |
{ "name": "Limit", "value": "tag_env_stage" } | |
], | |
"cron": "21 * * * *", | |
"disabled": true | |
}, | |
{ | |
"name": "Cron_Run_Ansible_QA", | |
"vars":[ | |
{ "name": "Branch", "value": "develop" }, | |
{ "name": "Inventory", "value": "ec2.py" }, | |
{ "name": "Limit", "value": "tag_env_qa" } | |
], | |
"cron": "22 * * * *", | |
"disabled": true | |
} | |
] | |
} | |
*/ | |
json.cronJobs.each { | |
name = it.name | |
vars = it.vars | |
cron = it.cron | |
disabled = it.disabled | |
job(name) { | |
logRotator(-1, 5, -1, -1) | |
disabled(disabled) | |
environmentVariables { | |
vars.each { | |
env(it.name, it.value) | |
} | |
keepBuildVariables(true) | |
} | |
steps { | |
downstreamParameterized { | |
trigger("Run_Ansible") { | |
block { | |
buildStepFailure("FAILURE") | |
failure("FAILURE") | |
unstable("UNSTABLE") | |
} | |
parameters { | |
predefinedProp("Branch", '${Branch}') | |
predefinedProp("Inventory", '${Inventory}') | |
predefinedProp("Limit", '${Limit}') | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
creating the downstreamParameterized build step took awhile to figure out .. also, how to BLOCK progress while calling a downstream job .. what's nice is we can manage all of this here and it will update the jobs when we make a change .. so how we change branches on a regular basis for an env, manage that here and commit and the HC room will be updated whenever we make a change .. can also create a nice hal command to show the contents of this so we can see what is enabled/disabled/etc ..