Repository navigation
Expand file tree
/
Copy pathJenkinsfile-RobotTests
More file actions
449 lines (427 loc) · 17.3 KB
/
Copy pathJenkinsfile-RobotTests
File metadata and controls
449 lines (427 loc) · 17.3 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
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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
#!/bin/groovy
/*
* SPDX-License-Identifier: MIT
*/
// Location of the CN executor node
def cn_ci_host = params.Host_CN_CI_Server
def cn_ci_resource = params.DockerContainers
def upstreamEvent = false
def upstreamIsFED = false
// Variables that can used in main pipeline and in functions
DEFAULT=-1
NRF=0
AMF=1
SMF=2
UPF=3
AUSF=4
UDM=5
UDR=6
NSSF=7
UPF_VPP=8
PCF=9
LMF=10
NORTH=11
// Default tags / branches --> could be passed on by upstream job
imageNames = ["oai-nrf", "oai-amf", "oai-smf", "oai-upf", "oai-ausf", "oai-udm", "oai-udr", "oai-nssf", "oai-upf-vpp", "oai-pcf", "oai-lmf"]
repoNames = ["oai-cn5g-nrf", "oai-cn5g-amf", "oai-cn5g-smf", "oai-cn5g-upf", "oai-cn5g-ausf", "oai-cn5g-udm", "oai-cn5g-udr", "oai-cn5g-nssf", "oai-cn5g-upf-vpp", "oai-cn5g-pcf", "oai-cn5g-lmf"]
branchNames = ["", "", "", "", "", "", "", "", "", "", ""]
imageTags = ["", "", "", "", "", "", "", "", "", "", ""]
upstreamJobs = [false, false, false, false, false, false, false, false, false, false, false]
pulledImages = [false, false, false, false, false, false, false, false, false, false, false]
// Which OMEC-GNBSIM TAG to use
upstreamTagToUse = params.upstreamTagToUse?.trim() ?: 'develop'
rfTags = ""
def sdk_credentials = params.Private_Repo_Credentials ?: 'github-jenkins-oai-cn'
// 5gcsdk branch and repository URL
def SDK_BRANCH = params.SDK_BRANCH ?: 'main'
def SDK_URL = params.SDK_URL ?: 'https://github.com/openairinterface/5gcsdk.git'
//-------------------------------------------------------------------------------
// Pipeline start
pipeline {
agent {
label cn_ci_host
}
options {
disableConcurrentBuilds()
timestamps()
ansiColor('xterm')
lock(cn_ci_resource)
}
stages {
stage ('Verify Parameters') {
steps {
deleteDir() // wipe workspace
checkout scm // get fresh code
script {
echo '\u2705 \u001B[32mVerify Parameters\u001B[0m'
JOB_TIMESTAMP = sh returnStdout: true, script: 'date --utc --rfc-3339=seconds | sed -e "s#+00:00##"'
JOB_TIMESTAMP = JOB_TIMESTAMP.trim()
echo "Node is ${NODE_NAME}"
// Find out the cause of the trigger
for (cause in currentBuild.getBuildCauses()) {
if (cause.toString().contains('UpstreamCause')) {
upstreamEvent = true
}
if (cause.toString().contains('OAI-CN5G-GitHub-NRF')) {
upstreamJobs[NRF] = true
}
if (cause.toString().contains('OAI-CN5G-GitHub-AMF')) {
upstreamJobs[AMF] = true
}
if (cause.toString().contains('OAI-CN5G-GitHub-SMF')) {
upstreamJobs[SMF] = true
}
if (cause.toString().contains('OAI-CN5G-GitHub-UPF')) {
upstreamJobs[UPF] = true
}
if (cause.toString().contains('OAI-CN5G-GitHub-AUSF')) {
upstreamJobs[AUSF] = true
}
if (cause.toString().contains('OAI-CN5G-GitHub-UDM')) {
upstreamJobs[UDM] = true
}
if (cause.toString().contains('OAI-CN5G-GitHub-UDR')) {
upstreamJobs[UDR] = true
}
if (cause.toString().contains('OAI-CN5G-GitHub-NSSF')) {
upstreamJobs[NSSF] = true
}
if (cause.toString().contains('OAI-CN5G-UPF-VPP')) {
upstreamJobs[UPF_VPP] = true
}
if (cause.toString().contains('OAI-CN5G-GitHub-PCF')) {
upstreamJobs[PCF] = true
}
if (cause.toString().contains('OAI-CN5G-GitHub-LMF')) {
upstreamJobs[LMF] = true
}
if (cause.toString().contains('OAI-CN5G-FED')) {
upstreamIsFED = true
}
}
sh "git clean -x -d -ff > /dev/null 2>&1"
sh "git submodule foreach --recursive 'git clean -x -d -ff' > /dev/null 2>&1"
sh "git submodule deinit --force --all > /dev/null 2>&1"
if (!upstreamIsFED) {
// Manual or NF-triggered build: test the requested fed branch or tag.
sh "git fetch --no-tags origin ${upstreamTagToUse}"
sh "git checkout -f FETCH_HEAD"
}
if (upstreamIsFED && params.GIT_MERGE_REF) {
// Fed PR: test the PR-merged-into-target state (GitHub's precomputed merge ref).
sh "git fetch origin ${params.GIT_MERGE_REF}"
sh "git checkout -f FETCH_HEAD"
} else if (upstreamIsFED && params.GIT_COMMIT_SHA) {
// Fed push: fetch first; the sha may be abbreviated.
sh "git fetch --no-tags --force origin '+refs/heads/*:refs/remotes/origin/*'"
sh "git checkout -f ${params.GIT_COMMIT_SHA}"
} else if (upstreamIsFED) {
error "FED-triggered build is missing GIT_MERGE_REF and GIT_COMMIT_SHA"
}
sh "echo Current commit after checkout is \$(git rev-parse HEAD)"
// Authenticate the submodule clone: -c scopes the credential helper to just this command.
withCredentials([
[$class: 'UsernamePasswordMultiBinding', credentialsId: 'github-jenkins-oai-cn', usernameVariable: 'GITHUB_USERNAME', passwordVariable: 'GITHUB_TOKEN']
]) {
sh '''
git -c credential.helper='!f() { echo "username=$GITHUB_USERNAME"; echo "password=$GITHUB_TOKEN"; }; f' submodule update --init --recursive ci-scripts/common
'''
}
sh "mkdir -p archives"
// Having the possibility to run manually as in CI
int emulation_run = params.EMULATE_MR_RUN.toInteger()
switch (emulation_run) {
case NRF:
upstreamEvent = true
upstreamJobs[NRF] = true
break
case AMF:
upstreamEvent = true
upstreamJobs[AMF] = true
break
case SMF:
upstreamEvent = true
upstreamJobs[SMF] = true
break
case UPF:
upstreamEvent = true
upstreamJobs[UPF] = true
break
case AUSF:
upstreamEvent = true
upstreamJobs[AUSF] = true
break
case UDM:
upstreamEvent = true
upstreamJobs[UDM] = true
break
case UDR:
upstreamEvent = true
upstreamJobs[UDR] = true
break
case NSSF:
upstreamEvent = true
upstreamJobs[NSSF] = true
break
case PCF:
upstreamEvent = true
upstreamJobs[PCF] = true
break
case LMF:
upstreamEvent = true
upstreamJobs[LMF] = true
break
case NORTH:
rfTags = rfTags + ' -i North '
break
case DEFAULT:
break
}
for (ii = 0; ii < imageNames.size(); ii++) {
if (ii == NRF) {
branchNames[NRF] = params.NRF_BRANCH
imageTags[NRF] = params.NRF_TAG
if (upstreamEvent && upstreamJobs[NRF]) {
rfTags = rfTags + ' -i NRF '
echo "Upstream Job passed NRF_TAG to use: ${imageTags[NRF]}"
echo "Upstream Job passed NRF_BRANCH to use: ${branchNames[NRF]}"
}
}
if (ii == AMF) {
branchNames[AMF] = params.AMF_BRANCH
imageTags[AMF] = params.AMF_TAG
if (upstreamEvent && upstreamJobs[AMF]) {
rfTags = rfTags + ' -i AMF '
echo "Upstream Job passed AMF_TAG to use: ${imageTags[AMF]}"
echo "Upstream Job passed AMF_BRANCH to use: ${branchNames[AMF]}"
}
}
if (ii == SMF) {
branchNames[SMF] = params.SMF_BRANCH
imageTags[SMF] = params.SMF_TAG
if (upstreamEvent && upstreamJobs[SMF]) {
rfTags = rfTags + ' -i SMF '
echo "Upstream Job passed SMF_TAG to use: ${imageTags[SMF]}"
echo "Upstream Job passed SMF_BRANCH to use: ${branchNames[SMF]}"
}
}
if (ii == UPF) {
branchNames[UPF] = params.UPF_BRANCH
imageTags[UPF] = params.UPF_TAG
if (upstreamEvent && upstreamJobs[UPF]) {
rfTags = rfTags + ' -i UPF '
echo "Upstream Job passed UPF_TAG to use: ${imageTags[UPF]}"
echo "Upstream Job passed UPF_BRANCH to use: ${branchNames[UPF]}"
}
}
if (ii == AUSF) {
branchNames[AUSF] = params.AUSF_BRANCH
imageTags[AUSF] = params.AUSF_TAG
if (upstreamEvent && upstreamJobs[AUSF]) {
rfTags = rfTags + ' -i AUSF '
echo "Upstream Job passed AUSF_TAG to use: ${imageTags[AUSF]}"
echo "Upstream Job passed AUSF_BRANCH to use: ${branchNames[AUSF]}"
}
}
if (ii == UDM) {
branchNames[UDM] = params.UDM_BRANCH
imageTags[UDM] = params.UDM_TAG
if (upstreamEvent && upstreamJobs[UDM]) {
rfTags = rfTags + ' -i UDM '
echo "Upstream Job passed UDM_TAG to use: ${imageTags[UDM]}"
echo "Upstream Job passed UDM_BRANCH to use: ${branchNames[UDM]}"
}
}
if (ii == UDR) {
branchNames[UDR] = params.UDR_BRANCH
imageTags[UDR] = params.UDR_TAG
if (upstreamEvent && upstreamJobs[UDR]) {
rfTags = rfTags + ' -i UDR '
echo "Upstream Job passed UDR_TAG to use: ${imageTags[UDR]}"
echo "Upstream Job passed UDR_BRANCH to use: ${branchNames[UDR]}"
}
}
if (ii == NSSF) {
branchNames[NSSF] = params.NSSF_BRANCH
imageTags[NSSF] = params.NSSF_TAG
if (upstreamEvent && upstreamJobs[NSSF]) {
rfTags = rfTags + ' -i NSSF '
echo "Upstream Job passed NSSF_TAG to use: ${imageTags[NSSF]}"
echo "Upstream Job passed NSSF_BRANCH to use: ${branchNames[NSSF]}"
}
}
if (ii == UPF_VPP) {
branchNames[UPF_VPP] = params.UPF_VPP_BRANCH
imageTags[UPF_VPP] = params.UPF_VPP_TAG
if (upstreamEvent && upstreamJobs[UPF_VPP]) {
rfTags = rfTags + ' -i UPF_VPP '
echo "Upstream Job passed UPF_VPP_TAG to use: ${imageTags[UPF_VPP]}"
echo "Upstream Job passed UPF_VPP_BRANCH to use: ${branchNames[UPF_VPP]}"
}
}
if (ii == PCF) {
branchNames[PCF] = params.PCF_BRANCH
imageTags[PCF] = params.PCF_TAG
if (upstreamEvent && upstreamJobs[PCF]) {
rfTags = rfTags + ' -i PCF '
echo "Upstream Job passed PCF_TAG to use: ${imageTags[PCF]}"
echo "Upstream Job passed PCF_BRANCH to use: ${branchNames[PCF]}"
}
}
if (ii == LMF) {
branchNames[LMF] = params.LMF_BRANCH
imageTags[LMF] = params.LMF_TAG
if (upstreamEvent && upstreamJobs[LMF]) {
rfTags = rfTags + ' -i LMF '
echo "Upstream Job passed LMF_TAG to use: ${imageTags[LMF]}"
echo "Upstream Job passed LMF_BRANCH to use: ${branchNames[LMF]}"
}
}
}
// On Ubuntu servers, we shall pull from private local registry
if ((cn_ci_host == 'Selfix') || (cn_ci_host == 'Alambix')) {
pullFromSelfix = true
try {
// Login
sh 'docker login -u oaicicd -p oaicicd gracehopper3-oai.sboai.cs.eurecom.fr > /dev/null 2>&1'
} catch (Exception e) {
echo 'Problem w/ selfix registry. Let see if we can use local images'
pullFromSelfix = false
}
if (pullFromSelfix) {
// We will try to pull from Selfix registry.
// If the NF CI is yet ready, it's OK, it will fail but keep working with local registry
for (ii = 0; ii < imageNames.size(); ii++) {
imageTags[ii] = pullImageFromSelfix(ii, imageNames[ii], imageTags[ii], branchNames[ii])
}
// Logout
sh 'docker logout gracehopper3-oai.sboai.cs.eurecom.fr > /dev/null 2>&1'
}
}
if (cn_ci_host == 'Alambix') {
// Forcing to run on Northbound testing on Alambix
// TODO: remove this when UPF-VPP runs again on Ubuntu-24
rfTags = '-i North '
}
// Verify that the images are available
imageStatus = 0
for (ii = 0; ii < imageNames.size(); ii++) {
imageStatus += checkImageInfo(imageNames[ii], imageTags[ii])
}
if (imageStatus > 0) {
error ("Some images are not present!")
}
}
// TODO: once the 5gcsdk repo is public, no longer needed.
// A git submodule approach would be better.
sh "rm -Rf test/5gcsdk"
sh "mkdir -p test/5gcsdk"
dir ('test/5gcsdk') {
checkout scmGit(
branches: [[name: "*/${SDK_BRANCH}"]],
extensions: [],
userRemoteConfigs: [[
credentialsId: sdk_credentials,
url: "${SDK_URL}"]])
}
// Making sure that the latest version of oai-gnb and oai-nr-ue develop images
// is on the test server
sh "docker pull oaisoftwarealliance/oai-gnb:develop || true"
sh "docker pull oaisoftwarealliance/oai-nr-ue:develop || true"
sh "docker image prune -f"
}
}
stage ('Run Robot Framework Tests') {
steps {
script {
for (ii = 0; ii < imageTags.size(); ii++) {
if (imageNames[ii] == "oai-upf-vpp" && imageTags[ii] == "develop") { // As UPF-VPP is no longer maintained
imageTags[ii] = "develop-863d2bf7"
}
prepareRobotImageTags(imageNames[ii], imageTags[ii])
}
sh 'robot ' + rfTags + ' --outputdir archives test'
}
}
}
}
post {
always {
script {
// Zipping all archived log files
if (fileExists('archives')) {
sh 'zip -r -qq cn5g_fed_robot_tests.zip archives'
archiveArtifacts artifacts: 'cn5g_fed_robot_tests.zip'
}
// archive robot framework log
if (fileExists('archives/log.html')) {
archiveArtifacts artifacts: 'archives/log.html, archives/report.html'
}
// We generate HTML report if we did not already
// we shall not fail in post section
if (!fileExists('test_results_robot_framework.html')) {
sh './ci-scripts/checkRobotFrameworkHtmlReport.py --job_name ' + JOB_NAME + ' --job_id ' + BUILD_ID + ' --job_url ' + BUILD_URL + ' || true'
}
if (fileExists('test_results_robot_framework.html')) {
if (JOB_NAME == 'OAI-CN5G-RobotTest-NorthBound-Testing') {
sh 'mv test_results_robot_framework.html test_results_robot_framework_northbound.html'
archiveArtifacts artifacts: 'test_results_robot_framework_northbound.html'
} else {
archiveArtifacts artifacts: 'test_results_robot_framework.html'
}
}
}
}
cleanup {
script {
sh 'docker volume prune --force'
// Removing the images that we pulled.
for (ii = 0; ii < imageNames.size(); ii++) {
if (pulledImages[ii]) {
sh 'docker rmi ' + imageNames[ii] + ':' + imageTags[ii]
}
}
}
}
}
}
def pullImageFromSelfix(idx, imageName, imageTag, branchName) {
if ((imageTag == 'develop') && (branchName == 'develop')) {
try {
tag = sh returnStdout: true, script: './ci-scripts/retrieveLatestTagOnPrivateRepo.py --repo-name ' + imageName
tag = tag.trim()
} catch (Exception e) {
return imageTag
}
} else {
tag = imageTag
}
// We may have wrong image tag?
try {
sh 'docker pull gracehopper3-oai.sboai.cs.eurecom.fr/' + imageName + ':' + tag
sh 'docker image tag gracehopper3-oai.sboai.cs.eurecom.fr/' + imageName + ':' + tag + ' ' + imageName + ':' + tag
sh 'docker rmi gracehopper3-oai.sboai.cs.eurecom.fr/' + imageName + ':' + tag
if (idx != -1) {
pulledImages[idx] = true
}
} catch (Exception e) {
echo "${imageName} Image tag to test (${imageName}:${tag} does not exist on selfix private registry!"
tag = imageTag
}
return tag
}
def checkImageInfo(imageName, origTag) {
status = 0
sh "echo 'Tested Tag is ${imageName}:${origTag}' > archives/${imageName}-image-info.log"
try {
sh "docker image inspect --format='Size = {{.Size}} bytes' ${imageName}:${origTag} >> archives/${imageName}-image-info.log"
sh "docker image inspect --format='Date = {{.Created}}' ${imageName}:${origTag} >> archives/${imageName}-image-info.log"
} catch (Exception e) {
echo "${imageName} Image tag to test (${imageName}:${origTag} does not exist!"
status = 1
}
return status
}
def prepareRobotImageTags(imageName, tag) {
sh 'sed -i -e "s@oaisoftwarealliance/' + imageName + ':develop@' + imageName + ':' + tag + '@" test/image_tags.py'
}