forked from electric-cloud/DSL-Samples
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathDeployAttachedPipelineRunApps.dsl
187 lines (178 loc) · 9.85 KB
/
DeployAttachedPipelineRunApps.dsl
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/*
CloudBees CD DSL: Deploy only the applications with associated attached pipelines
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 just the applications for which there is an associated attached pipeline run. In this
example, the application name and pipeline definition names are the same. This example also shows how data from the
attached pipeline runs can be pulled into the release pipeline.
Instructions
0. Run this DSL (ectool evalDsl --dslFile DeployAttachedPipelineRunApps.dsl, or import and run from the DSLIDE)
1. Start the application pipelines
2. Start the release
3. Attach two of the pipeline runs to the release
4. Approve the release manual task
- The "Deploy selected applications" task should have deployed the application associated with the pipeline you
attached
- Note that links to the attached pipeline runs are provided in first stage summary as is the feature list gathered
from the attached pipelines.
5. You can attach or detach pipeline runs then restart the "Gather evidence task" to see the effect
*/
def Apps = ["App1","App2","App3"]
project "Deploy Attached", {
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'
}
}
}
pipeline App,{
stage "Build",{
task "Get feature list",{
taskType = 'COMMAND'
subpluginKey = 'EC-Core'
subprocedure = 'RunCommand'
actualParameter = [
commandToRun: '''\
ectool setProperty "/myPipelineRuntime/features" --value $[/javascript
function onlyUnique(value, index, self) {
return self.indexOf(value) === index;
}
var c = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ\'
var key = c.charAt(Math.random() * c.length) + c.charAt(Math.random() * c.length) + c.charAt(Math.random() * c.length)
var number = Math.trunc(Math.random() * 10000)
var features = []
for (i=0;i<Math.random() * 20;i++) \tfeatures.push(key + "-" + Math.trunc(number + Math.random() * 20))
features.filter(onlyUnique).join(",")
]
'''.stripIndent()
]
}
}
stage "Testing"
stage "Join Release",{
gate 'PRE', {
task 'Wait', {
gateCondition = 'true'
gateType = 'PRE'
precondition = 'false'
taskType = 'CONDITIONAL'
}
}
}
}
release "Sample Release",{
pipeline "Release Pipeline",{
stage "QA",{
task 'Attach Pipeline Runs', {
instruction = 'Attach desired pipeline runs'
taskType = 'MANUAL'
approver = [getProperty(propertyName: "/myUser/userName").value]
}
task 'Gather evidence',{
taskType = 'COMMAND'
subpluginKey = 'EC-Core'
subprocedure = 'RunCommand'
actualParameter = [
commandToRun: '''\
/*
- Create stage summary links for the attached pipeline runs
- Create a comma separted list of attached runtime pipeline IDs as a release pipeline runtime property
*/
import com.electriccloud.client.groovy.ElectricFlow
ElectricFlow ef = new ElectricFlow()
def attachedPipelines = ef.getAttachedPipelineRuns(
projectName: "$[/myPipelineRuntime/projectName]",
releaseName: "$[/myRelease]"
).attachedPipelineRunDetail
def flowRuntimeIds = []
def features = []
def attachedLink = "\\n\\n<html><ul>"
attachedPipelines.each { attachedPipeline ->
def pipelineId = ef.getProperty(
flowRuntimeId: attachedPipeline.flowRuntimeId,
propertyName: "/myPipeline/pipelineId"
).property.value
features.addAll(ef.getProperty(
flowRuntimeId: attachedPipeline.flowRuntimeId,
propertyName: "/myPipelineRuntime/features"
).property.value.split(","))
attachedLink += """<li><a href="#pipeline-run/${pipelineId}/${attachedPipeline.flowRuntimeId}">${attachedPipeline.flowRuntimeName}</a></li>"""
flowRuntimeIds.push(attachedPipeline.flowRuntimeId)
}
attachedLink += "</ul></html>"
ef.setProperty(
propertyName: "/myPipelineRuntime/attachedPipelines",
value: flowRuntimeIds.join(",")
)
ef.setProperty(
propertyName: "/myStageRuntime/ec_summary/Attached Pipelines",
value: attachedLink
)
ef.setProperty(
propertyName: "/myStageRuntime/ec_summary/Features",
value: features.join(",")
)
'''.stripIndent(),
]
}
task 'Deploy selected applications', {
taskType = 'DEPLOYER'
deployerExpression = '''\
var items=[];
var attachedRuns = api.getAttachedPipelineRuns(
{projectName: myPipelineRuntime.projectName,
releaseName: myPipelineRuntime.releaseName}
).attachedPipelineRunDetail
if (typeof(attachedRuns)!=='undefined') for (i=0; i < attachedRuns.length; i++) {
var attached = api.getProperty(
{flowRuntimeId: attachedRuns[i].flowRuntimeId,
propertyName: "/myPipelineRuntime/pipelineName"}
).property.value
for(var j=0;j<itemList.length;j++){
var item = itemList[j];
if (item == attached) 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"
}
}
}
}
}
}