Last active
November 11, 2019 12:23
-
-
Save JD10NN3/cb44137a94111cf9693c7815d26fa919 to your computer and use it in GitHub Desktop.
Example of a External Jenkins Pipeline mapping
This file contains 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
/* | |
This is used as part of a dynamic Jenkins pipeline configuration. | |
You can reference to this Gist for more details: | |
https://gist.github.com/JD10NN3/7796639e4d427d474c172d5e6b0fa49a | |
*/ | |
this.map = [ | |
/** | |
* Sandbox1 mapping | |
* | |
* Change the branch name below to rebuild Sandbox1 with the | |
* sources of that specific branch | |
*/ | |
"Story/0001": [ | |
[ | |
// Targeted environment | |
"env" : "sandbox1", | |
// Who is using that environment | |
"owner" : "John Doh", | |
// The steps with want for that specific environment | |
"stages": [ | |
// This is kind of mandatory... if we want to build something. | |
"checkout": [], | |
// The build process with some options. | |
// In this case, we don't want to archive the deployment package. | |
"build" : ["archive": false, "command": "war"], | |
// We want to run tests. | |
"tests" : [], | |
// We want an approval before doing the deployment. | |
// This is to avoid troubles with a resources who is using the targeted env. | |
// eg.: devs, testers... | |
"deploy" : ["approval": true], | |
] | |
] | |
], | |
/** | |
* Sandbox2 mapping | |
*/ | |
"Story/0002": [ | |
[ | |
"env" : "sandbox2", | |
"owner" : "Jane Doh", | |
"stages": [ | |
"checkout": [], | |
"build" : ["archive": false, "command": "war"], | |
"tests" : [], | |
"deploy" : ["approval": true], | |
] | |
] | |
], | |
/** | |
* Master and Integration mappings | |
*/ | |
"master": [ | |
[ | |
"env" : "prod", | |
"owner" : "Integration Squad", | |
"stages": [ | |
"checkout": [], | |
// The package is going to be deployed manually in production. | |
// So, we must keep an archive to be able to do the deployment later. | |
"build" : ["archive": true, "command": "war"], | |
] | |
] | |
], | |
"integration": [ | |
[ | |
"env" : "intg", | |
"owner" : "Integration Squad", | |
"stages": [ | |
"checkout": [], | |
"build" : ["archive": false, "command": "war"], | |
"deploy" : ["approval": false], | |
] | |
], [ | |
"env" : "prep", | |
"owner" : "Integration Squad", | |
"stages": [ | |
"build" : ["archive": false, "command": "war"], | |
"tests" : [], | |
"deploy": ["approval": true], | |
] | |
] | |
], | |
] | |
/** | |
* The default mapping | |
*/ | |
this.defaultMap = [ | |
[ | |
"owner" : "", | |
"env" : "local", | |
"stages": [ | |
"checkout": [], | |
// We only want to make sure that the local build works | |
// To achieve this add avoid losing computation time | |
// we set the command to main. (no war generated) | |
"build" : ["archive": false, "command": "main"], | |
] | |
], [ | |
"owner" : "", | |
"env" : "intg", | |
"stages": [ | |
"build" : ["archive": false, "command": "war"], | |
"tests" : [], | |
] | |
] | |
] | |
/** | |
* Get mapping for a specific branch name. | |
* If no match is found, default mapping is returned | |
* | |
* @param branch name | |
* @return default or specific mapping based on branch name provided | |
*/ | |
def getFor(branch) { | |
return this.map.getOrDefault(branch, defaultMap) | |
} | |
return this |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment