forked from electric-cloud/DSL-Samples
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathDeployAppsByReleaseParameter.dsl
More file actions
130 lines (118 loc) · 4.84 KB
/
Copy pathDeployAppsByReleaseParameter.dsl
File metadata and controls
130 lines (118 loc) · 4.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
CloudBees CD DSL: Deploy parameter-selected applications attached to a Release
CloudBees CD release models support deploying applications in bulk. However, it may be that for a particular release
run, you only want to run a subset of the applications that are configured for the release definition. This sample
project illustrates how to deploy based on check box parameters.
Instructions
------------
0. Run this DSL (ectool evalDsl --dslFile DeployAppsByReleaseParameter.dsl, or import and run from the DSLIDE)
1. Start the release and select the applications to be deployed. Note that that an additional (unused) parameter is
revealed when a particular application parameter is toggled on. This illustrates the use of parameter render
conditions.
The "Deploy selected applications" task should have deployed the application associated with the pipeline you attached
Deployer Condition development tips
-----------------------------------
It is possible to debug the Deployer Condition code by running and rerunning the Deployer task in a pipeline. For complex
you code, might consider an IDE or an on-line tool like https://www.webtoolkitonline.com/javascript-tester.html to do your
development. If you go this route, you'll need to provide the runtime values that you plan to use:
applicationList – An array of applications added to the release
serviceList – An array of services added to the release
itemList – An array of applications and services added to the release
deployerTask - Current task
myPipelineRuntime.actualParameters - Pipeline parameters
And, you'll want to use JSON.stringify instead of "return" to view the results. Here is a sample testbed for the
Deployer Condition used in this example:
// Sample runtime values
var itemList=["App1","App2","App3"]
var myPipelineRuntime={
"actualParameters":{
"App1":"true",
"App1_arg":"ABC",
"App2":"false",
"App2_arg":"",
"App3":"true",
"App3_arg":"123",
}
}
// The code under development
var items = [];
for(Apps=0;Apps<itemList.length;Apps++){
var item= itemList[Apps];
if (myPipelineRuntime.actualParameters[item] == 'true') items.push(item)
}
//return items; // Remember to uncomment this
// View the object
JSON.stringify(items)
*/
def Apps = ["App1","App2","App3"]
project "Deploy Selected", {
environment "QA", {
environmentTier "App", {
resource "${projectName}_${environmentName}_${environmentTierName}",
hostName: getResource(resourceName: "local").hostName
}
}
Apps.each { App ->
application App, {
applicationTier "App"
tierMap 'QA', {
applicationName = applicationName
environmentName = 'QA'
environmentProjectName = projectName
tierMapping 'App-App', {
applicationTierName = 'App'
environmentTierName = 'App'
}
}
process "Deploy",{
processStep 'NOP', {
actualParameter = [
commandToRun: 'echo',
]
applicationTierName = 'App'
processStepType = 'command'
subprocedure = 'RunCommand'
subproject = '/plugins/EC-Core/project'
}
}
} // application
release "Sample Release",{
pipeline "Release Pipeline",{
formalParameter App,{
defaultValue = 'false'
checkedValue = 'true'
type = 'checkbox'
uncheckedValue = 'false'
}
formalParameter "${App}_arg", defaultValue: '', {
dependsOn = App
renderCondition = "\${${App}}=='true'"
}
stage "QA",{
task 'Deploy selected applications', {
taskType = 'DEPLOYER'
deployerExpression = '''\
var items = [];
for(Apps=0;Apps<itemList.length;Apps++){
var item= itemList[Apps];
if (myPipelineRuntime.actualParameters[item] == 'true') items.push(item)
}
return items;
'''.stripIndent()
}
}
stage "Staging"
stage "Production"
}
deployerApplication App, {
processName = 'Deploy'
deployerConfiguration 'QA', {
deployerTaskName = 'Deploy selected applications'
environmentName = 'QA'
processName = 'Deploy'
stageName = "QA"
}
}
} // release
} // Apps.each
} // project