forked from electric-cloud/DSL-Samples
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathEndRelease.groovy
127 lines (108 loc) · 3.59 KB
/
EndRelease.groovy
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
/*
Pipeline that can run asynchrously in a Release to end the release and set the ACL to Deny everyone write and execute permissions. This ensures no one can alter the Properties of the Release after it is closed
*/
project 'CloudBees', {
pipeline 'EndRelease', {
projectName = 'CloudBees'
formalParameter 'ReleaseName', defaultValue: '$[/myPipelineRuntime/releaseName]', {
orderIndex = '1'
required = '1'
type = 'entry'
}
formalParameter 'RuntimeID', defaultValue: '$[/myPipelineRuntime/flowRuntimeId]', {
orderIndex = '2'
required = '1'
type = 'entry'
}
formalParameter 'ReleaseProjectName', defaultValue: '$[/myPipelineRuntime/projectName]', {
orderIndex = '3'
required = '1'
type = 'entry'
}
formalParameter 'ReleaseID', defaultValue: '$[/myPipelineRuntime/releaseId]', {
orderIndex = '4'
required = '1'
type = 'entry'
}
formalParameter 'ec_stagesToRun', {
expansionDeferred = '1'
}
stage 'EndRelease', {
colorCode = '#289ce1'
pipelineName = 'EndRelease'
task 'EndRelease', {
actualParameter = [
'ReleaseID': '$[/myPipelineRuntime/ReleaseID]',
'ReleaseName': '$[/myPipelineRuntime/ReleaseName]',
'ReleaseProjectName': '$[/myPipelineRuntime/ReleaseProjectName]',
'RuntimeID': '$[/myPipelineRuntime/RuntimeID]',
]
subprocedure = 'EndRelease'
subproject = 'CloudBees'
taskType = 'PROCEDURE'
}
}
// Custom properties
}
procedure 'EndRelease', {
projectName = 'CloudBees'
timeLimit = '0'
formalParameter 'ReleaseProjectName', {
orderIndex = '1'
required = '1'
type = 'entry'
}
formalParameter 'RuntimeID', {
orderIndex = '2'
required = '1'
type = 'entry'
}
formalParameter 'ReleaseName', {
orderIndex = '3'
required = '1'
type = 'entry'
}
formalParameter 'ReleaseID', {
orderIndex = '4'
required = '1'
type = 'entry'
}
step 'End Release', {
command = '''import com.electriccloud.client.groovy.ElectricFlow
ElectricFlow ef = new ElectricFlow()
// Specify the length of time to wait in seconds.
int waitFor = 30;
int retries = 10
for ( int i = 0; i < retries; i++ ) {
def result = ef.getPipelineRuntimeDetails(flowRuntimeIds: [\'$[/myJob/RuntimeID]\'])
def completed = result.flowRuntime[0].completed
println(result)
if (completed == "1")
{
println(ef.completeRelease( projectName: "$[/myJob/ReleaseProjectName]", releaseName: "$[/myJob/ReleaseName]" ))
System.exit(0)
}
println("Release has not completed yet.")
Thread.sleep(waitFor * 1000);
}
println("Release did not complete withing the specified wait time.")
System.exit(1)'''
errorHandling = 'abortProcedureNow'
procedureName = 'EndRelease'
shell = 'ec-groovy'
timeLimit = '0'
timeLimitUnits = 'seconds'
}
step 'ModifyACL', {
description = 'Deny Modify Permissions for Everyone'
command = '''import com.electriccloud.client.groovy.ElectricFlow
ElectricFlow ef = new ElectricFlow()
ef.createAclEntry(objectId: "release-$[/myJob/ReleaseID]", principalType:"group",principalName:"Everyone",readPrivilege:"allow",modifyPrivilege:"deny",executePrivilege:"deny",changePermissionsPrivilege:"deny")'''
errorHandling = 'abortProcedureNow'
procedureName = 'EndRelease'
shell = 'ec-groovy'
timeLimit = '0'
timeLimitUnits = 'seconds'
}
}
}