This repository has been archived by the owner on Nov 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 95
/
Copy pathJenkinsfile
279 lines (259 loc) · 10.7 KB
/
Jenkinsfile
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
#!/usr/bin/groovy
VDVS_65_NODE_NAME = ""
VDVS_65_NODE_ID = ""
VDVS_60_NODE_NAME = ""
VDVS_60_NODE_ID = ""
pipeline {
agent none
stages {
stage('Select slaves') {
failFast true
parallel {
stage('Select slave for ESX 6.5 runs') {
agent { label "vdvs-65-slaves && available" }
steps {
script {
VDVS_65_NODE_NAME = env.NODE_NAME
VDVS_65_NODE_ID = UUID.randomUUID().toString()
replaceNodeLabel(VDVS_65_NODE_NAME, "available", VDVS_65_NODE_ID)
}
sleep 2
}
}
stage('Select slave for ESX 6.0 runs') {
agent { label "vdvs-60-slaves && available" }
steps {
script {
VDVS_60_NODE_NAME = env.NODE_NAME
VDVS_60_NODE_ID = UUID.randomUUID().toString()
replaceNodeLabel(VDVS_60_NODE_NAME, "available", VDVS_60_NODE_ID)
}
sleep 2
}
}
}
}
stage('Checkout code') {
failFast true
parallel {
stage('Checkout for ESX 6.5 runs') {
/* Let's make sure we have the repository cloned to our workspace. */
steps {
node (VDVS_65_NODE_ID as String) {
checkout scm
}
}
}
stage('Checkout for ESX 6.0 runs') {
/* Let's make sure we have the repository cloned to our workspace..*/
steps {
node (VDVS_60_NODE_ID as String) {
checkout scm
}
}
}
}
}
stage('Build binaries') {
/* This builds VDVS binaries */
failFast true
parallel {
stage('Build binaries for ESX 6.5 runs') {
steps {
node (VDVS_65_NODE_ID as String) {
echo "Building the VDVS binaries"
sh "export PKG_VERSION=$BUILD_NUMBER"
sh "make build-all"
}
}
}
stage('Build binaries for ESX 6.0 runs') {
steps {
node (VDVS_60_NODE_ID as String) {
echo "Building the VDVS binaries"
sh "export PKG_VERSION=$BUILD_NUMBER"
sh "make build-all"
}
}
}
}
}
stage('Deployment') {
failFast true
parallel {
stage('Deploy binaries for ESX 6.5 runs') {
steps {
node (VDVS_65_NODE_ID as String) {
echo "Deployment On 6.5 setup"
echo "ESX=$ESX; VM1=$VM1; VM2=$VM2; VM3=$VM3; PKG_VERSION"
sh "make deploy-all"
echo "Finished deploying the binaries"
}
}
}
stage('Deploy binaries for ESX 6.0 runs') {
steps {
node (VDVS_60_NODE_ID as String) {
echo "Deployment On 6.0 setup"
echo "ESX=$ESX; VM1=$VM1; VM2=$VM2; VM3=$VM3; PKG_VERSION"
echo "Deploying binaries"
sh "make deploy-all"
echo "Finished deploying the binaries"
}
}
}
}
}
stage('Test VDVS') {
failFast true
parallel {
stage('Run tests on ESX 6.5') {
steps {
node (VDVS_65_NODE_ID as String) {
script {
try {
echo "Test VDVS On 6.5 setup"
echo " ESX=$ESX, VM1=$VM1, VM2=$VM2, VM3=$VM3, PKG_VERSION"
echo " starting e2e tests"
sh "make test-e2e"
sh "make test-esx"
sh "make test-vm"
}
catch (ex) {
cleanSetup(false)
throw ex
}
}
}
}
}
stage('Run tests on ESX 6.0') {
steps {
node (VDVS_60_NODE_ID as String) {
script {
try {
echo "Test VDVS On 6.0 setup"
echo "ESX=$ESX, VM1=$VM1, VM2=$VM2, echo VM3=$VM3, echo PKG_VERSION"
echo "Starting e2e tests"
sh "make test-e2e"
sh "make test-esx"
sh "make test-vm"
}
catch (ex) {
cleanSetup(false)
throw ex
}
}
}
}
}
}
}
stage('Test vFile') {
failFast true
parallel {
stage('Run vFile tests on ESX 6.5') {
steps {
node (VDVS_65_NODE_ID as String) {
script {
try {
echo "Build, deploy, and test vFile on 6.5 setup"
echo "Build vFile binaries"
echo "ESX = $ESX, VM1=$VM1, VM2=$VM2, VM3=$VM3;"
sh "make build-vfile-all"
echo " Deploy the vFile binaries"
sh "make deploy-vfile-plugin"
echo "Start the vFile tests"
sh "make test-e2e-vfile"
echo "vFile tests finished"
} finally {
cleanSetup(true)
}
}
}
}
}
stage('Run vFile tests on ESX 6.0') {
steps {
node (VDVS_60_NODE_ID as String) {
script{
try {
echo "Build, deploy, and test vFile on 6.0 setup"
echo "Build vFile binaries"
echo "ESX=$ESX, VM1=$VM1, VM2=$VM2, VM3=$VM3;"
sh "make build-vfile-all"
echo " Deploy the vFile binaries"
sh "make deploy-vfile-plugin"
echo "Run the vFile tests"
sh "make test-e2e-vfile"
echo "vFile tests finished"
} finally {
cleanSetup(true)
}
}
}
}
}
}
}
stage('Test Windows plugin') {
/* This builds, deploys and tests the windows binaries */
steps {
node (VDVS_65_NODE_ID as String) {
echo "Build, deploy, and test Windows plugin"
echo "Windows-VM=$WIN_VM1"
echo "Build Windows plugin binaries"
sh "make build-windows-plugin"
echo "Finished building binaries for windows"
echo "Deploy the Windows plugin binaries"
sh "make deploy-windows-plugin"
echo "echo Finished deploying binaries for windows"
echo "echo Run the Windows plugin tests"
sh "make test-e2e-windows"
echo "Windows plugin tests finished"
}
}
}
}
// The options directive is for configuration that applies to the whole job.
options {
// This ensures we only have 10 builds at a time, so
// we don't fill up our storage!
buildDiscarder(logRotator(numToKeepStr: '10'))
}
post {
always {
script {
echo "Resetting nodes..."
replaceNodeLabel(VDVS_65_NODE_NAME, VDVS_65_NODE_ID, "available")
replaceNodeLabel(VDVS_60_NODE_NAME, VDVS_60_NODE_ID, "available")
echo "Reset complete!"
}
}
}
}
def replaceNodeLabel(nodeName, oldLabel, newLabel) {
echo "Replacing label for node: " + nodeName + ", oldLabel: " + oldLabel + ", newLabel: " + newLabel
def jk = jenkins.model.Jenkins.instance
def node = jk.getNode(nodeName)
node.labelString = node.labelString.replaceAll("\\b " + oldLabel + "\\b", "")
node.labelString = node.labelString + " " + newLabel
node.save()
}
def cleanSetup(cleanVfile) {
echo "Cleaning up the setup..."
echo "ESX = $ESX; VM1=$VM1; VM2=$VM2; VM3=$VM3;"
echo "bool=$cleanVfile"
def stopContainers = "docker stop \$(docker ps -a -q) 2> /dev/null || true"
def removeContainers = "docker rm \$(docker ps -a -q) 2> /dev/null || true"
def removeVolumes = "docker volume rm \$(docker volume ls -q -f dangling=true) 2> /dev/null || true"
sh "ssh ${env.GOVC_USERNAME}@$VM1 ${stopContainer}; ${removeContainer}; ${removeVolume}"
sh "ssh ${env.GOVC_USERNAME}@$VM2 ${stopContainer}; ${removeContainer}; ${removeVolume}"
sh "ssh ${env.GOVC_USERNAME}@$VM3 ${stopContainer}; ${removeContainer}; ${removeVolume}"
if (cleanVfile) {
echo "Removing vFile plugin..."
sh "make clean-vfile"
}
sh "make clean-all"
echo "Cleanup finished!"
}