-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathJenkinsfile.functional
335 lines (335 loc) · 16.6 KB
/
Jenkinsfile.functional
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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
def RunPowershellCommand(psCmd) {
bat "powershell.exe -NonInteractive -ExecutionPolicy Bypass -Command \"[Console]::OutputEncoding=[System.Text.Encoding]::UTF8;$psCmd;EXIT \$global:LastExitCode\""
}
pipeline {
agent {
node {
label '3rd-CIBUS'
customWorkspace "workspace/pipeline-func-${env.BUILD_ID}"
}
}
environment {
RHEL_VER = sh(returnStdout: true, script: "[[ $version = 4.* ]] && echo '8' || echo '7'").trim()
API_PORT = sh(returnStdout: true, script: 'awk -v min=1025 -v max=9999 \'BEGIN{srand(); print int(min+rand()*(max-min+1))}\'').trim()
HV = sh(returnStdout: true, script: """
if [[ $release = *"hyperv"* ]] || [[ $release = *"hyper-v"* ]] || [[ $release = *"hyper"* ]]; then
echo "1"
elif [[ $release = *"esxi"* ]] || [[ $release = *"esx"* ]]; then
echo "2"
else
echo "3"
fi
""").trim()
FROM = credentials('email-3rd-qe-list')
SMTP = credentials('smtp-server-address')
TASK_URL_PREFIX = credentials('task-url-prefix')
}
stages {
stage('Omni Server Provision') {
environment {
PUBLIC_KEY = credentials('3rd_id_rsa_pub')
NFS_IP = credentials('nfs-ip')
NFS_PATH = credentials('nfs-path')
}
steps {
script {
currentBuild.displayName = "${env.owner}-${env.version}-${env.release}-${env.id}"
}
echo 'Running Omni Container...'
sh """
sudo docker network inspect jenkins >/dev/null 2>&1 || sudo docker network create jenkins
sudo docker pull henrywangxf/jenkins:latest
sudo docker ps --quiet --all --filter 'name=omni-func-${API_PORT}' | sudo xargs --no-run-if-empty docker rm -f
sudo docker volume ls --quiet --filter 'name=kernels-volume-func-${API_PORT}' | sudo xargs --no-run-if-empty docker volume rm
sudo docker volume inspect nfs-func-${API_PORT} > /dev/null 2>&1 || \
sudo docker volume create --driver local \
--opt type=nfs --opt o=addr=${NFS_IP} --opt device=:${NFS_PATH} nfs-func-${API_PORT}
sudo docker run -d --name omni-func-${API_PORT} --restart=always \
-p ${API_PORT}:22 -v kernels-volume-func-${API_PORT}:/kernels -v nfs-func-${API_PORT}:/kernels/nfs \
--network jenkins --security-opt label=disable \
-e AUTHORIZED_KEYS=\"${PUBLIC_KEY}\" \
henrywangxf/jenkins:latest
"""
sh 'printenv'
cleanWs()
}
}
stage('Kernel Download') {
environment {
BREW_API = credentials('3rd-brew-api-address')
}
steps {
echo 'Downloading kernel rpm...'
sh """
sudo docker ps --quiet --all --filter 'name=download-func-${API_PORT}' | sudo xargs --no-run-if-empty docker rm -f
sudo docker run --rm --name download-func-${API_PORT} \
-v kernels-volume-func-${API_PORT}:/kernels --network jenkins \
henrywangxf/jenkins:latest \
python3 kbot.py ${name}-${version}-${release} ${BREW_API} --download --id ${id} --path /kernels
"""
echo "API_PORT: ${API_PORT}"
cleanWs()
}
}
stage('Functional Test') {
environment {
DOMAIN = credentials('hyperv-domain-login')
VSPHERE = credentials('fd83fe98-2754-4985-9276-12fbbf73d3bf')
OMNI_IP = credentials('omni-server-ip')
OMNI_USER = credentials('omni-scp-username')
ENVVISIPADDR = credentials('vsphere-ip')
ENVVISPROTOCOL = 'HTTPS'
}
parallel {
stage('Hyper-V 2016 Gen2') {
options {
timeout(time: 6, unit: 'HOURS')
}
environment {
HOST_ID = '2016-AUTO'
IMAGE = "image-2016-${RHEL_VER}.vhdx"
}
agent {
node {
label '3rd-CIVAN'
customWorkspace "workspace/pipeline-2016-g2-${env.BUILD_ID}"
}
}
when {
expression { HV == '1' || HV == '3'}
}
steps {
echo 'Checkout VM Provision Code'
checkout scm
echo 'Gen2 VM Provision on 2016'
powershell 'Get-ChildItem Env:'
RunPowershellCommand(".\\runner.ps1 -action add -dual -gen2")
echo 'Checkout LISA Code'
checkout changelog: false, poll: false, scm: [$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'lis']], submoduleCfg: [], userRemoteConfigs: [[url: 'https://github.com/LIS/lis-test.git']]]
RunPowershellCommand(".\\runner.ps1 -action run -dual -gen2")
}
post {
always {
// Delete VM(s)
RunPowershellCommand(".\\runner.ps1 -action del -dual -gen2")
// Upload result to omni server
RunPowershellCommand(".\\runner.ps1 -action put -dual -gen2")
// Clear workspace
cleanWs()
}
}
}
stage('Hyper-V 2012R2 Gen1') {
options {
timeout(time: 6, unit: 'HOURS')
}
environment {
HOST_ID = '2012R2-AUTO'
IMAGE = "image-2012r2-${RHEL_VER}.vhdx"
}
agent {
node {
label '3rd-CIVAN'
customWorkspace "workspace/pipeline-2012r2-g1-${env.BUILD_ID}"
}
}
when {
expression { HV == '1' || HV == '3'}
}
steps {
echo 'Checkout VM Provision Code'
checkout scm
echo 'Gen1 VM Provision on 2012R2'
RunPowershellCommand(".\\runner.ps1 -action add -dual")
echo 'Checkout LISA Code'
checkout changelog: false, poll: false, scm: [$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'lis']], submoduleCfg: [], userRemoteConfigs: [[url: 'https://github.com/LIS/lis-test.git']]]
RunPowershellCommand(".\\runner.ps1 -action run -dual")
}
post {
always {
// Delete VM(s)
RunPowershellCommand(".\\runner.ps1 -action del -dual")
// Upload result to omni server
RunPowershellCommand(".\\runner.ps1 -action put -dual")
// Clear workspace
cleanWs()
}
}
}
stage('Hyper-V 2012 Gen1') {
options {
timeout(time: 6, unit: 'HOURS')
}
environment {
HOST_ID = '2012-72-132'
IMAGE = "image-2012-${RHEL_VER}.vhdx"
}
agent {
node {
label '3rd-CIVAN'
customWorkspace "workspace/pipeline-2012-g1-${env.BUILD_ID}"
}
}
when {
expression { HV == '1' || HV == '3'}
}
steps {
echo 'Checkout VM Provision Code'
checkout scm
echo 'Gen1 VM Provision on 2012'
RunPowershellCommand(".\\runner.ps1 -action add -dual")
echo 'Checkout LISA Code'
checkout changelog: false, poll: false, scm: [$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'lis']], submoduleCfg: [], userRemoteConfigs: [[url: 'https://github.com/LIS/lis-test.git']]]
RunPowershellCommand(".\\runner.ps1 -action run -dual")
}
post {
always {
// Delete VM(s)
RunPowershellCommand(".\\runner.ps1 -action del -dual")
// Upload result to omni server
RunPowershellCommand(".\\runner.ps1 -action put -dual")
// Clear workspace
cleanWs()
}
}
}
stage('ESXi 6.7 BIOS') {
options {
timeout(time: 2, unit: 'HOURS')
}
environment {
HOST_ID = '10.73.196.97'
IMAGE = "image-67-${RHEL_VER}.ova"
}
agent {
node {
label '3rd-CIVAN'
customWorkspace "workspace/pipeline-6.7-bios-${env.BUILD_ID}"
}
}
when {
expression { HV == '2' || HV == '3'}
}
steps {
echo 'Checkout VM Provision Code'
checkout scm
echo 'EFI VM Provision on ESXi 6.7'
RunPowershellCommand(".\\runner.ps1 -action add -dual -esxi")
echo 'Checkout LISA Code'
checkout changelog: false, poll: false, scm: [$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'lis']], submoduleCfg: [], userRemoteConfigs: [[url: 'https://github.com/VirtQE-S1/ESX-LISA.git']]]
RunPowershellCommand(".\\runner.ps1 -action run -dual -esxi")
}
post {
always {
// Delete VM(s)
RunPowershellCommand(".\\runner.ps1 -action del -dual -esxi")
// Upload result to omni server
RunPowershellCommand(".\\runner.ps1 -action put")
// Clear workspace
cleanWs()
}
}
}
stage('ESXi 6.5 EFI') {
options {
timeout(time: 2, unit: 'HOURS')
}
environment {
HOST_ID = '10.73.72.129'
IMAGE = "image-65-${RHEL_VER}.ova"
}
agent {
node {
label '3rd-CIVAN'
customWorkspace "workspace/pipeline-6.5-efi-${env.BUILD_ID}"
}
}
when {
expression { HV == '2' || HV == '3'}
}
steps {
echo 'Checkout VM Provision Code'
checkout scm
echo 'EFI VM Provision on ESXi 6.5'
RunPowershellCommand(".\\runner.ps1 -action add -dual -gen2 -esxi")
echo 'Checkout LISA Code'
checkout changelog: false, poll: false, scm: [$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'lis']], submoduleCfg: [], userRemoteConfigs: [[url: 'https://github.com/VirtQE-S1/ESX-LISA.git']]]
RunPowershellCommand(".\\runner.ps1 -action run -dual -gen2 -esxi")
}
post {
always {
// Delete VM(s)
RunPowershellCommand(".\\runner.ps1 -action del -dual -gen2 -esxi")
// Upload result to omni server
RunPowershellCommand(".\\runner.ps1 -action put")
// Clear workspace
cleanWs()
}
}
}
stage('ESXi 6.0 BIOS') {
options {
timeout(time: 2, unit: 'HOURS')
}
environment {
HOST_ID = '10.73.196.236'
IMAGE = "image-60-${RHEL_VER}.ova"
}
agent {
node {
label '3rd-CIVAN'
customWorkspace "workspace/pipeline-6.0-bios-${env.BUILD_ID}"
}
}
when {
expression { HV == '2' || HV == '3'}
}
steps {
echo 'Checkout VM Provision Code'
checkout scm
echo 'EFI VM Provision on ESXi 6.0'
RunPowershellCommand(".\\runner.ps1 -action add -dual -esxi")
echo 'Checkout LISA Code'
checkout changelog: false, poll: false, scm: [$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'lis']], submoduleCfg: [], userRemoteConfigs: [[url: 'https://github.com/VirtQE-S1/ESX-LISA.git']]]
RunPowershellCommand(".\\runner.ps1 -action run -dual -esxi")
}
post {
always {
// Delete VM(s)
RunPowershellCommand(".\\runner.ps1 -action del -dual -esxi")
// Upload result to omni server
RunPowershellCommand(".\\runner.ps1 -action put")
// Clear workspace
cleanWs()
}
}
}
}
}
}
post {
always {
echo 'Stop and remove omni container'
echo 'Start result analyzer and email sender container'
echo 'Remove volume'
sh """
sudo docker ps --quiet --all --filter 'name=omni-func-${API_PORT}' | sudo xargs --no-run-if-empty docker rm -f
sudo docker run --rm --name mailbot-${API_PORT} \
-v kernels-volume-func-${API_PORT}:/kernels --network jenkins \
henrywangxf/jenkins:latest \
python3 ./mailbot.py --path /kernels --mail ${FROM} --task ${TASK_URL_PREFIX} --smtp ${SMTP} --hv ${HV}
sudo docker volume ls --quiet --filter 'name=kernels-volume-func-${API_PORT}' | sudo xargs --no-run-if-empty docker volume rm
sudo docker volume ls --quiet --filter 'name=nfs-func-${API_PORT}' | sudo xargs --no-run-if-empty docker volume rm
"""
// sudo docker volume ls --quiet --filter 'name=kernels-volume-${API_PORT}' | sudo xargs --no-run-if-empty docker volume rm
// sudo docker rmi -f henrywangxf/jenkins:latest
cleanWs()
}
}
options {
skipDefaultCheckout()
timestamps()
buildDiscarder(logRotator(numToKeepStr:'10'))
timeout(time: 6, unit: 'HOURS')
}
}