Jenkinsfile-gitlab 38.1 KB
Newer Older
1
#!/bin/groovy
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
 * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The OpenAirInterface Software Alliance licenses this file to You under
 * the OAI Public License, Version 1.1  (the "License"); you may not use this file
 * except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.openairinterface.org/?page_id=698
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *-------------------------------------------------------------------------------
 * For more information about the OpenAirInterface (OAI) Software Alliance:
 *      contact@openairinterface.org
 */
22

23 24 25 26 27 28 29 30 31 32
// Abstraction function to send social media messages:
// like on Slack or Mattermost
def sendSocialMediaMessage(pipeChannel, pipeColor, pipeMessage) {
    if (params.pipelineUsesSlack != null) {
        if (params.pipelineUsesSlack) {
            slackSend channel: pipeChannel, color: pipeColor, message: pipeMessage
        }
    }
}

33 34
// Location of the executor node
def nodeExecutor = params.nodeExecutor
Raphael Defosseux's avatar
CI:  
Raphael Defosseux committed
35

36 37 38
// VM Lockable resources
def vmResource = params.vmLockableResource

39 40 41 42
// Tags to shorten pipeline duration
def doMandatoryTests = false
def doFullTestsuite = false

43 44
pipeline {
    agent {
45
        label nodeExecutor
46 47 48 49 50
    }
    options {
        disableConcurrentBuilds()
        timestamps()
        gitLabConnection('OAI GitLab')
Raphael Defosseux's avatar
CI:  
Raphael Defosseux committed
51
        ansiColor('xterm')
52 53 54
    }

    stages {
Raphael Defosseux's avatar
CI:  
Raphael Defosseux committed
55 56 57
        stage ("Verify Parameters") {
            steps {
                script {
58 59 60
                    JOB_TIMESTAMP = sh returnStdout: true, script: 'date --utc --rfc-3339=seconds | sed -e "s#+00:00##"'
                    JOB_TIMESTAMP = JOB_TIMESTAMP.trim()

Raphael Defosseux's avatar
CI:  
Raphael Defosseux committed
61 62
                    echo '\u2705 \u001B[32mVerify Parameters\u001B[0m'
                    def allParametersPresent = true
63 64
                    if (env.TESTPLATFORM_OWNER) {
                        echo "Platform is ${env.TESTPLATFORM_OWNER}"
Raphael Defosseux's avatar
Raphael Defosseux committed
65
                    }
Raphael Defosseux's avatar
CI:  
Raphael Defosseux committed
66

67 68 69
                    if (fileExists("flexran")) {
                        sh "rm -Rf flexran > /dev/null 2>&1"
                    }
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

                    echo '\u2705 \u001B[32mVerify Labels\u001B[0m'
                    if ("MERGE".equals(env.gitlabActionType)) {
                        LABEL_CHECK = sh returnStdout: true, script: 'ci-scripts/checkGitLabMergeRequestLabels.sh --mr-id ' + env.gitlabMergeRequestIid
                        LABEL_CHECK = LABEL_CHECK.trim()
                        if (LABEL_CHECK == 'NONE') {
                            def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): Your merge request has none of the mandatory labels:\n\n"
                            message += " - BUILD-ONLY\n"
                            message += " - 4G-LTE\n"
                            message += " - 5G-NR\n"
                            message += " - CI\n\n"
                            message += "Not performing CI due to lack of labels"
                            addGitLabMRComment comment: message
                            error('Not performing CI due to lack of labels')
                        } else if (LABEL_CHECK == 'FULL') {
                            doMandatoryTests = true
                            doFullTestsuite = true
                        } else if (LABEL_CHECK == 'SHORTEN-5G') {
                            doMandatoryTests = true
                        } else {
                            def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): We will perform only build stages on your Merge Request"
                            addGitLabMRComment comment: message
                        }
                    } else {
                        doMandatoryTests = true
                        doFullTestsuite = true
                    }
Raphael Defosseux's avatar
CI:  
Raphael Defosseux committed
97 98 99
                }
            }
        }
100
        stage ("Verify Guidelines") {
101 102 103 104 105
            steps {
                echo "Git URL         is ${GIT_URL}"
                echo "GitLab Act      is ${env.gitlabActionType}"
                script {
                    if ("MERGE".equals(env.gitlabActionType)) {
106
                        // since a bit, in push events, gitlabUserEmail is not populated
107
                        gitCommitAuthorEmailAddr = env.gitlabUserEmail
108
                        echo "GitLab Usermail is ${gitCommitAuthorEmailAddr}"
109
                        // GitLab-Jenkins plugin integration is lacking to perform the merge by itself
110
                        // Doing it manually --> it may have merge conflicts
111
                        sh "./ci-scripts/doGitLabMerge.sh --src-branch ${env.gitlabSourceBranch} --src-commit ${env.gitlabMergeRequestLastCommit} --target-branch ${env.gitlabTargetBranch} --target-commit ${GIT_COMMIT}"
112
                        sh "zip -r -qq localZip.zip ."
113 114 115 116

                        // Running astyle options on the list of modified files by the merge request
                        // For the moment, there is no fail criteria. Just a notification of number of files that do not follow
                        sh "./ci-scripts/checkCodingFormattingRules.sh --src-branch ${env.gitlabSourceBranch} --target-branch ${env.gitlabTargetBranch}"
117 118
                        def res=readFile('./oai_rules_result.txt').trim();
                        if ("0".equals(res)) {
119 120
                            def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): All Changed files in Merge Request follow OAI Formatting Rules"
                            addGitLabMRComment comment: message
121
                        } else {
122 123
                            def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): Some Changed files in Merge Request DO NOT follow OAI Formatting Rules"
                            addGitLabMRComment comment: message
124 125 126 127
                        }
                    } else {
                        echo "Git Branch      is ${GIT_BRANCH}"
                        echo "Git Commit      is ${GIT_COMMIT}"
128 129 130 131
                        // since a bit, in push events, gitlabUserEmail is not populated
                        gitCommitAuthorEmailAddr = sh returnStdout: true, script: 'git log -n1 --pretty=format:%ae ${GIT_COMMIT}'
                        gitCommitAuthorEmailAddr = gitCommitAuthorEmailAddr.trim()
                        echo "GitLab Usermail is ${gitCommitAuthorEmailAddr}"
132
                        sh "git log -n1 --pretty=format:\"%s\" > .git/CI_COMMIT_MSG"
133

134
                        sh "zip -r -qq localZip.zip ."
135 136
                        // Running astyle options on all C/H files in the repository
                        // For the moment, there is no fail criteria. Just a notification of number of files that do not follow
137
                        sh "./ci-scripts/checkCodingFormattingRules.sh"
138
                    }
139 140 141
                    // With Mosaic 5G being part of OSA and making all it's repositories public
                    // No need to pass credentials to clone flexran-rtc
                    if (doMandatoryTests) {
142 143
                        sh "mkdir flexran"
                        dir ('flexran') {
144 145
                            sh "git clone https://gitlab.eurecom.fr/flexran/flexran-rtc.git . > ../git_clone.log 2>&1"
                            sh "git checkout develop >> ../git_clone.log 2>&1"
146 147 148
                            sh "zip -r -qq flexran.zip ."
                        }
                    }
149 150
                }
            }
151 152
            post {
                failure {
153 154 155
                    script {
                        def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): Merge Conflicts -- Cannot perform CI"
                        addGitLabMRComment comment: message
Boris Djalal's avatar
Boris Djalal committed
156
                        currentBuild.result = 'FAILURE'
157
                    }
158 159
                }
            }
160
        }
161

162
        stage ("Start VM -- basic-sim") {
163
            steps {
164
              lock (vmResource) {
165
                timeout (time: 5, unit: 'MINUTES') {
166
                    sh "./ci-scripts/oai-ci-vm-tool build --workspace $WORKSPACE --variant basic-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID} --daemon"
167
                }
168
              }
169 170 171
            }
        }

172
        stage ("Start VM -- gnb-usrp") {
173
            steps {
174
              lock (vmResource) {
175
                timeout (time: 5, unit: 'MINUTES') {
176
                    sh "./ci-scripts/oai-ci-vm-tool build --workspace $WORKSPACE --variant gnb-usrp --job-name ${JOB_NAME} --build-id ${BUILD_ID} --daemon"
177
                }
178
              }
179 180 181
            }
        }

182
        stage ("Start VM -- nr-ue-usrp") {
183
            steps {
184
              lock (vmResource) {
185
                timeout (time: 5, unit: 'MINUTES') {
186
                    sh "./ci-scripts/oai-ci-vm-tool build --workspace $WORKSPACE --variant nr-ue-usrp --job-name ${JOB_NAME} --build-id ${BUILD_ID} --daemon"
187
                }
188
              }
189 190 191
            }
        }

192
        stage ("Start VM -- enb-ethernet") {
193
            steps {
194
              lock (vmResource) {
195
                timeout (time: 7, unit: 'MINUTES') {
196
                    sh "./ci-scripts/oai-ci-vm-tool build --workspace $WORKSPACE --variant enb-ethernet --job-name ${JOB_NAME} --build-id ${BUILD_ID} --daemon"
197
                }
198
              }
199 200 201
            }
        }

202
        stage ("Start VM -- ue-ethernet") {
203
            steps {
204
              lock (vmResource) {
205
                timeout (time: 7, unit: 'MINUTES') {
206
                    sh "./ci-scripts/oai-ci-vm-tool build --workspace $WORKSPACE --variant ue-ethernet --job-name ${JOB_NAME} --build-id ${BUILD_ID} --daemon"
207
                }
208
              }
209
            }
210
   }
211
        
212 213
        stage ("Variant Builds") {
            parallel {
214
                stage ("Build basic simulator") {
215
                    steps {
216
                        gitlabCommitStatus(name: "Build basic-sim") {
217
                            timeout (time: 45, unit: 'MINUTES') {
218
                                sh "./ci-scripts/oai-ci-vm-tool wait --workspace $WORKSPACE --variant basic-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep-vm-alive"
219
                            }
220 221 222
                        }
                    }
                }
223
                stage ("Build 5G gNB-USRP") {
224
                    steps {
225
                        gitlabCommitStatus(name: "Build gNB-USRP") {
226
                            timeout (time: 45, unit: 'MINUTES') {
227
                                sh "./ci-scripts/oai-ci-vm-tool wait --workspace $WORKSPACE --variant gnb-usrp --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep-vm-alive"
228
                            }
229 230
                        }
                    }
231
                }
232
                stage ("Build 5G NR-UE-USRP") {
233
                    steps {
234
                        gitlabCommitStatus(name: "Build nr-UE-USRP") {
235
                            timeout (time: 45, unit: 'MINUTES') {
236
                                sh "./ci-scripts/oai-ci-vm-tool wait --workspace $WORKSPACE --variant nr-ue-usrp --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep-vm-alive"
237
                            }
238 239 240
                        }
                    }
                }
241
                stage ("Build eNB-ethernet") {
242
                    steps {
243
                        gitlabCommitStatus(name: "Build eNB-ethernet") {
244
                            timeout (time: 45, unit: 'MINUTES') {
245
                                sh "./ci-scripts/oai-ci-vm-tool wait --workspace $WORKSPACE --variant enb-ethernet --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep-vm-alive"
246
                            }
247 248 249
                        }
                    }
                }
250
                stage ("Build UE-ethernet") {
251
                    steps {
252 253
                      // This is typically the last one to finish.
                      lock (vmResource) {
254
                        gitlabCommitStatus(name: "Build UE-ethernet") {
255
                            timeout (time: 45, unit: 'MINUTES') {
256
                                sh "./ci-scripts/oai-ci-vm-tool wait --workspace $WORKSPACE --variant ue-ethernet --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep-vm-alive"
257
                            }
258
                        }
259
                      }
260 261
                    }
                }
262 263
            }
            post {
Boris Djalal's avatar
Boris Djalal committed
264 265 266 267 268
                failure {
                    script {
                        currentBuild.result = 'FAILURE'
                    }
                }
269 270
                always {
                    script {
271
                        dir ('archives') {
272
                            if (fileExists('red_hat')) {
273
                                sh "zip -r -qq vm_build_logs.zip basic_sim enb_eth ue_eth gnb_usrp nr_ue_usrp red_hat"
274
                            } else {
275
                                sh "zip -r -qq vm_build_logs.zip basic_sim enb_eth ue_eth gnb_usrp nr_ue_usrp"
276
                            }
277 278 279
                        }
                        if(fileExists('archives/vm_build_logs.zip')) {
                            archiveArtifacts artifacts: 'archives/vm_build_logs.zip'
280 281
                        }
                        if ("MERGE".equals(env.gitlabActionType)) {
282
                            sh "./ci-scripts/oai-ci-vm-tool report-build --workspace $WORKSPACE --git-url ${GIT_URL} --job-name ${JOB_NAME} --build-id ${BUILD_ID} --trigger merge-request --src-branch ${env.gitlabSourceBranch} --src-commit ${env.gitlabMergeRequestLastCommit} --target-branch ${env.gitlabTargetBranch} --target-commit ${GIT_COMMIT}"
283
                            // If the merge request has introduced compilation warnings, notifications in GitLab
Raphael Defosseux's avatar
CI:  
Raphael Defosseux committed
284 285 286 287 288
                            sh "./ci-scripts/checkAddedWarnings.sh --src-branch ${env.gitlabSourceBranch} --target-branch ${env.gitlabTargetBranch}"
                            def res=readFile('./oai_warning_files.txt').trim();
                            if ("0".equals(res)) {
                                echo "No issues w/ warnings/errors in this merge request"
                            } else {
289
                                def fileList=readFile('./oai_warning_files_list.txt').trim();
Raphael Defosseux's avatar
CI:  
Raphael Defosseux committed
290 291 292
                                def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): Some modified files in Merge Request MAY have INTRODUCED WARNINGS (" + fileList + ")"
                                addGitLabMRComment comment: message
                            }
293
                        } else {
294
                            sh "./ci-scripts/oai-ci-vm-tool report-build --workspace $WORKSPACE --git-url ${GIT_URL} --job-name ${JOB_NAME} --build-id ${BUILD_ID} --trigger push --branch ${GIT_BRANCH} --commit ${GIT_COMMIT}"
295 296
                        }
                        if(fileExists('build_results.html')) {
297
                            sh "sed -i -e 's#Build-ID: ${BUILD_ID}#Build-ID: <a href=\"${BUILD_URL}\">${BUILD_ID}</a>#' -e 's#TEMPLATE_BUILD_TIME#${JOB_TIMESTAMP}#' build_results.html"
298 299 300 301 302 303
                            archiveArtifacts artifacts: 'build_results.html'
                        }
                    }
                }
            }
        }
Raphael Defosseux's avatar
Raphael Defosseux committed
304

Raphael Defosseux's avatar
Raphael Defosseux committed
305 306
        stage ("Variant Tests") {
            parallel {
307 308 309 310
                stage ("VM-based tests") {
                    stages {
                        stage ("Build Flexran Controller") {
                            when {
311
                                expression {doMandatoryTests}
312 313
                            }
                            steps {
314
                              lock (vmResource) {
315 316 317 318 319 320 321 322
                                script {
                                    timeout (time: 20, unit: 'MINUTES') {
                                        try {
                                            sh "./ci-scripts/oai-ci-vm-tool build --workspace $WORKSPACE --variant flexran-rtc --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep-vm-alive"
                                        } catch (Exception e) {
                                          currentBuild.result = 'FAILURE'
                                        }
                                    }
323
                                }
324
                              }
325
                            }
326
                        }
327
                        stage ("Test basic simulator") {
328 329 330
                            when {
                                expression {doMandatoryTests}
                            }
331
                            steps {
332
                              lock (vmResource) {
333
                                script {
Raphael Defosseux's avatar
Raphael Defosseux committed
334 335 336
                                    timeout (time: 30, unit: 'MINUTES') {
                                        try {
                                            gitlabCommitStatus(name: "Test basic-sim") {
337 338
                                                sh "./ci-scripts/oai-ci-vm-tool test --workspace $WORKSPACE --variant basic-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
                                            }
Raphael Defosseux's avatar
Raphael Defosseux committed
339 340
                                        } catch (Exception e) {
                                          currentBuild.result = 'FAILURE'
341
                                        }
342 343
                                    }
                                }
344
                              }
345
                            }
346
                        }
347
                        stage ("Test L1 simulator") {
348 349 350
                            when {
                                expression {doMandatoryTests}
                            }
351
                            steps {
352
                              lock (vmResource) {
353 354 355 356 357 358 359 360 361 362 363
                                script {
                                    timeout (time: 30, unit: 'MINUTES') {
                                        try {
                                            gitlabCommitStatus(name: "Test L1-sim") {
                                                sh "./ci-scripts/oai-ci-vm-tool test --workspace $WORKSPACE --variant l1-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep-vm-alive"
                                            }
                                        } catch (Exception e) {
                                            currentBuild.result = 'FAILURE'
                                        }
                                    }
                                }
364
                              }
365
                            }
Raphael Defosseux's avatar
Raphael Defosseux committed
366
                        }
367
                        stage ("Test RF simulator") {
368 369 370
                            when {
                                expression {doMandatoryTests}
                            }
371
                            steps {
372
                              lock (vmResource) {
373
                                script {
374
                                    timeout (time: 40, unit: 'MINUTES') {
375 376 377 378 379 380 381
                                        try {
                                            gitlabCommitStatus(name: "Test RF-sim") {
                                                sh "./ci-scripts/oai-ci-vm-tool test --workspace $WORKSPACE --variant rf-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep-vm-alive"
                                            }
                                        } catch (Exception e) {
                                            currentBuild.result = 'FAILURE'
                                        }
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400
                                    }
                                }
                              }
                            }
                        }
                        stage ("Test 5G RF simulator") {
                            when {
                                expression {doMandatoryTests}
                            }
                            steps {
                              lock (vmResource) {
                                script {
                                    timeout (time: 40, unit: 'MINUTES') {
                                        try {
                                            gitlabCommitStatus(name: "Test 5G RF-sim") {
                                                sh "./ci-scripts/oai-ci-vm-tool test --workspace $WORKSPACE --variant rf5g-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep-vm-alive"
                                            }
                                        } catch (Exception e) {
                                            currentBuild.result = 'FAILURE'
401
                                        }
402 403
                                    }
                                }
404
                              }
405
                            }
406
                        }
407
                        stage ("Destroy all Virtual Machines") {
408 409 410
                            when {
                                expression {doMandatoryTests}
                            }
411
                            steps {
412
                              lock (vmResource) {
413
                                sh "./ci-scripts/oai-ci-vm-tool destroy --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
414
                              }
415
                            }
416
                        }
Raphael Defosseux's avatar
Raphael Defosseux committed
417 418
                    }
                }
419
                stage ("Test MONOLITHIC - FDD - Band 7 - B210") {
420 421 422
                    when {
                        expression {doFullTestsuite}
                    }
Raphael Defosseux's avatar
Raphael Defosseux committed
423
                    steps {
424
                        script {
425
                            triggerSlaveJob ('eNB-CI-FDD-Band7-B210', 'Test-Mono-FDD-Band7')
426 427 428 429 430
                        }
                    }
                    post {
                        always {
                            script {
431
                                finalizeSlaveJob('eNB-CI-FDD-Band7-B210')
432 433
                            }
                        }
434 435 436
                        failure {
                            script {
                                currentBuild.result = 'FAILURE'
437
                            }
438
                        }
Raphael Defosseux's avatar
Raphael Defosseux committed
439 440
                    }
                }
441
                stage ("Test MONOLITHIC - TDD - Band 40 - B210") {
442 443 444
                    when {
                        expression {doFullTestsuite}
                    }
445 446
                    steps {
                        script {
447
                            triggerSlaveJob ('eNB-CI-TDD-Band40-B210', 'Test-Mono-TDD-Band40')
448 449 450 451 452
                        }
                    }
                    post {
                        always {
                            script {
453
                                finalizeSlaveJob('eNB-CI-TDD-Band40-B210')
454 455
                            }
                        }
456 457 458
                        failure {
                            script {
                                currentBuild.result = 'FAILURE'
459 460
                            }
                        }
461 462
                    }
                }
463
                stage ("Test IF4p5 - FDD - Band 7 - B210") {
464 465 466
                    when {
                        expression {doFullTestsuite}
                    }
467 468
                    steps {
                        script {
Raphael Defosseux's avatar
Raphael Defosseux committed
469
                            sh "sleep 60"
470
                            triggerSlaveJob ('eNB-CI-IF4p5-FDD-Band7-B210', 'Test-IF4p5-FDD-Band7')
471 472 473 474 475
                        }
                    }
                    post {
                        always {
                            script {
476
                                finalizeSlaveJob('eNB-CI-IF4p5-FDD-Band7-B210')
477 478
                            }
                        }
479
                        failure {
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502
                            script {
                                currentBuild.result = 'FAILURE'
                            }
                        }
                    }
                }
                stage ("Test F1 - FDD - Band 7 - B210") {
                    when {
                        expression {doFullTestsuite}
                    }
                    steps {
                        script {
                            sh "sleep 60"
                            triggerSlaveJob ('eNB-CI-F1-FDD-Band7-B210', 'Test-F1-FDD-Band7')
                        }
                    }
                    post {
                        always {
                            script {
                                finalizeSlaveJob('eNB-CI-F1-FDD-Band7-B210')
                            }
                        }
                        failure {
503 504
                            script {
                                currentBuild.result = 'FAILURE'
505 506
                            }
                        }
507 508
                    }
                }
509
                stage ("Test IF4p5 - TDD - Band 40 - B210") {
510 511 512
                    when {
                        expression {doFullTestsuite}
                    }
513 514
                    steps {
                        script {
Raphael Defosseux's avatar
Raphael Defosseux committed
515
                            sh "sleep 60"
516
                            triggerSlaveJob ('eNB-CI-IF4p5-TDD-Band40-B210', 'Test-IF4p5-TDD-Band40')
517 518 519 520 521
                        }
                    }
                    post {
                        always {
                            script {
522
                                finalizeSlaveJob('eNB-CI-IF4p5-TDD-Band40-B210')
Raphael Defosseux's avatar
CI:  
Raphael Defosseux committed
523 524
                            }
                        }
525 526 527
                        failure {
                            script {
                                currentBuild.result = 'FAILURE'
528
                            }
529 530
                        }
                    }
531
                }
532
                stage ("Test MONOLITHIC - FDD - Band 13 - B210") {
533 534 535
                    when {
                        expression {doFullTestsuite}
                    }
536 537
                    steps {
                        script {
Raphael Defosseux's avatar
Raphael Defosseux committed
538
                            sh "sleep 60"
539
                            triggerSlaveJob ('eNB-CI-MONO-FDD-Band13-B210', 'Test-Mono-FDD-Band13-LTE-M')
540 541
                        }
                    }
542 543 544
                    post {
                        always {
                            script {
545
                                finalizeSlaveJob('eNB-CI-MONO-FDD-Band13-B210')
546 547 548 549 550
                            }
                        }
                        failure {
                            script {
                                currentBuild.result = 'FAILURE'
551 552
                            }
                        }
553 554
                    }
                }
555
                stage ("Test X2 Handover - FDD - Band 13 - B210") {
556 557 558
                    when {
                        expression {doFullTestsuite}
                    }
559 560
                    steps {
                        script {
561
                            sh "sleep 60"
562
                            triggerSlaveJob ('eNB-CI-MONO-FDD-Band13-X2HO-B210', 'Test-Mono-FDD-Band13-X2-HO')
563 564 565 566 567
                        }
                    }
                    post {
                        always {
                            script {
568
                                finalizeSlaveJob('eNB-CI-MONO-FDD-Band13-X2HO-B210')
569 570 571 572 573
                            }
                        }
                        failure {
                            script {
                                currentBuild.result = 'FAILURE'
574 575 576 577 578
                            }
                        }
                    }
                }
                stage ("Test IF4p5 - TDD - Band 38 - B210 - MultiRRU") {
579 580 581
                    when {
                        expression {doFullTestsuite}
                    }
582 583 584 585 586 587 588 589 590 591 592 593 594 595
                    steps {
                        script {
                            triggerSlaveJob ('eNB-CI-IF4p5-TDD-Band38-MultiRRU-B210', 'Test-IF4p5-TDD-Band38-Multi-RRU')
                        }
                    }
                    post {
                        always {
                            script {
                                finalizeSlaveJob('eNB-CI-IF4p5-TDD-Band38-MultiRRU-B210')
                            }
                        }
                        failure {
                            script {
                                currentBuild.result = 'FAILURE'
596 597 598 599
                            }
                        }
                    }
                }
Raphael Defosseux's avatar
Raphael Defosseux committed
600
                stage ("Test OAI UE - FDD - Band 20 - B200") {
601 602 603
                    when {
                        expression {doFullTestsuite}
                    }
604 605
                    steps {
                        script {
606
                            triggerSlaveJobNoGitLab ('UE-CI-FDD-Band20-B200')
607 608 609 610 611
                        }
                    }
                    post {
                        always {
                            script {
612
                                finalizeSlaveJob('UE-CI-FDD-Band20-B200')
Raphael Defosseux's avatar
Raphael Defosseux committed
613 614 615 616 617
                            }
                        }
                        failure {
                            script {
                                currentBuild.result = 'FAILURE'
618
                            }
619 620
                        }
                    }
Raphael Defosseux's avatar
Raphael Defosseux committed
621 622
                }
                stage ("Test OAI UE - OAI eNB - FDD - Band 7 - B200") {
623 624 625
                    when {
                        expression {doFullTestsuite}
                    }
Raphael Defosseux's avatar
Raphael Defosseux committed
626 627 628 629 630 631 632
                    steps {
                        script {
                            // Delayed trigger on slave job, so it is always the last one to run
                            sh "sleep 240"
                            triggerSlaveJob ('eNB-UE-CI-MONO-FDD-Band7-B200', 'Test-eNB-OAI-UE-FDD-Band7')
                        }
                    }
633 634 635
                    post {
                        always {
                            script {
636
                                finalizeSlaveJob('eNB-UE-CI-MONO-FDD-Band7-B200')
637 638 639 640 641
                            }
                        }
                        failure {
                            script {
                                currentBuild.result = 'FAILURE'
642 643
                            }
                        }
644
                    }
645
                }
646
                stage ("Test OAI NR UE - OAI gNB - TDD - Band 78 - N300") {
647 648 649
                    when {
                        expression {doMandatoryTests}
                    }
650 651 652 653 654 655 656 657 658 659 660 661 662 663
                    steps {
                        script {
                            triggerSlaveJob ('gNB-nrUE-MONO-TDD-Band78-N300', 'Test-TDD-Band78-gNB-NR-UE')
                        }
                    }
                    post {
                        always {
                            script {
                                finalizeSlaveJob('gNB-nrUE-MONO-TDD-Band78-N300')
                            }
                        }
                        failure {
                            script {
                                currentBuild.result = 'FAILURE'
664 665 666 667 668
                            }
                        }
                    }
                }
                stage ("Test OAI OCP-eNB - FDD - Band 7 - B210") {
669 670 671
                    when {
                        expression {doFullTestsuite}
                    }
672 673 674 675 676 677 678 679 680 681 682 683 684 685
                    steps {
                        script {
                            triggerSlaveJob ('OCPeNB-FDD-Band7-B210', 'Test-OCP-FDD-Band7')
                        }
                    }
                    post {
                        always {
                            script {
                                finalizeSlaveJob('OCPeNB-FDD-Band7-B210')
                            }
                        }
                        failure {
                            script {
                                currentBuild.result = 'FAILURE'
686 687 688 689
                            }
                        }
                    }
                }
Raphael Defosseux's avatar
Raphael Defosseux committed
690 691 692 693
            }
            post {
                always {
                    script {
694
                      if (doMandatoryTests) {
Raphael Defosseux's avatar
Raphael Defosseux committed
695
                        dir ('archives') {
696
                            sh "if [ -d basic_sim/test ] || [ -d rf_sim/test ] || [ -d l2_sim/test ]; then zip -r -qq vm_tests_logs.zip */test ; fi"
Raphael Defosseux's avatar
Raphael Defosseux committed
697 698 699
                        }
                        if(fileExists('archives/vm_tests_logs.zip')) {
                            archiveArtifacts artifacts: 'archives/vm_tests_logs.zip'
700
                            if ("MERGE".equals(env.gitlabActionType)) {
701
                                sh "./ci-scripts/oai-ci-vm-tool report-test --workspace $WORKSPACE --git-url ${GIT_URL} --job-name ${JOB_NAME} --build-id ${BUILD_ID} --trigger merge-request --src-branch ${env.gitlabSourceBranch} --src-commit ${env.gitlabMergeRequestLastCommit} --target-branch ${env.gitlabTargetBranch} --target-commit ${GIT_COMMIT}"
702
                            } else {
703
                                sh "./ci-scripts/oai-ci-vm-tool report-test --workspace $WORKSPACE --git-url ${GIT_URL} --job-name ${JOB_NAME} --build-id ${BUILD_ID} --trigger push --branch ${GIT_BRANCH} --commit ${GIT_COMMIT}"
704 705
                            }
                            if(fileExists('test_simulator_results.html')) {
706
                                sh "sed -i -e 's#Build-ID: ${BUILD_ID}#Build-ID: <a href=\"${BUILD_URL}\">${BUILD_ID}</a>#' -e 's#TEMPLATE_BUILD_TIME#${JOB_TIMESTAMP}#' test_simulator_results.html"
707 708
                                archiveArtifacts artifacts: 'test_simulator_results.html'
                            }
Raphael Defosseux's avatar
Raphael Defosseux committed
709
                        }
710
                      }
Raphael Defosseux's avatar
Raphael Defosseux committed
711 712 713 714
                    }
                }
            }
        }
715 716 717
    }
    post {
        always {
718
            script {
Raphael Defosseux's avatar
Raphael Defosseux committed
719
                // Stage destroy may not be run if error in previous stage
720
                sh "./ci-scripts/oai-ci-vm-tool destroy --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
721 722
                emailext attachmentsPattern: '*results*.html',
                     body: '''Hi,
723

724 725 726 727 728 729
Here are attached HTML report files for $PROJECT_NAME - Build # $BUILD_NUMBER - $BUILD_STATUS!

Regards,
OAI CI Team''',
                     replyTo: 'no-reply@openairinterface.org',
                     subject: '$PROJECT_NAME - Build # $BUILD_NUMBER - $BUILD_STATUS!',
730
                     to: gitCommitAuthorEmailAddr
731 732 733 734

                if (fileExists('.git/CI_COMMIT_MSG')) {
                    sh "rm -f .git/CI_COMMIT_MSG"
                }
735
            }
736 737 738
        }
        success {
            script {
739
                def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): passed (" + BUILD_URL + ")"
740 741 742
                if ("MERGE".equals(env.gitlabActionType)) {
                    echo "This is a MERGE event"
                    addGitLabMRComment comment: message
743
                    def message2 = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): passed (" + BUILD_URL + ") -- MergeRequest #" + env.gitlabMergeRequestIid + " (" + env.gitlabMergeRequestTitle + ")"
744
                    sendSocialMediaMessage('ci-enb', 'good', message2)
745
                } else {
746
                    sendSocialMediaMessage('ci-enb', 'good', message)
747 748 749 750 751
                }
            }
        }
        failure {
            script {
752
                def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): failed (" + BUILD_URL + ")"
753 754 755
                if ("MERGE".equals(env.gitlabActionType)) {
                    echo "This is a MERGE event"
                    addGitLabMRComment comment: message
756
                    def message2 = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): failed (" + BUILD_URL + ") -- MergeRequest #" + env.gitlabMergeRequestIid + " (" + env.gitlabMergeRequestTitle + ")"
757
                    sendSocialMediaMessage('ci-enb', 'danger', message2)
758
                } else {
759
                    sendSocialMediaMessage('ci-enb', 'danger', message)
760 761 762 763 764
                }
            }
        }
    }
}
765 766 767 768

// ----  Slave Job functions

def triggerSlaveJob (jobName, gitlabStatusName) {
769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788
    // Workaround for the "cancelled" GitLab pipeline notification
    // The slave job is triggered with the propagate false so the following commands are executed
    // Its status is now PASS/SUCCESS from a stage pipeline point of view
    // localStatus variable MUST be analyzed to properly assess the status
    localStatus = build job: jobName,
        parameters: [
            string(name: 'eNB_Repository', value: String.valueOf(GIT_URL)),
            string(name: 'eNB_Branch', value: String.valueOf(env.gitlabSourceBranch)),
            string(name: 'eNB_CommitID', value: String.valueOf(env.gitlabMergeRequestLastCommit)),
            booleanParam(name: 'eNB_mergeRequest', value: "MERGE".equals(env.gitlabActionType)),
            string(name: 'eNB_TargetBranch', value: String.valueOf(env.gitlabTargetBranch))
        ], propagate: false
    localResult = localStatus.getResult()
    echo "${jobName} Slave Job status is ${localResult}"
    gitlabCommitStatus(name: gitlabStatusName) {
        if (localStatus.resultIsBetterOrEqualTo('SUCCESS')) {
           echo "${jobName} Slave Job is OK"
        } else {
           echo "${jobName} Slave Job is KO"
           sh "ci-scripts/fail.sh"
789 790 791 792 793
        }
    }
}

def triggerSlaveJobNoGitLab (jobName) {
794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809
    // Workaround for the "cancelled" GitLab pipeline notification
    // The slave job is triggered with the propagate false so the following commands are executed
    // Its status is now PASS/SUCCESS from a stage pipeline point of view
    // localStatus variable MUST be analyzed to properly assess the status
    localStatus = build job: jobName,
        parameters: [
            string(name: 'eNB_Repository', value: String.valueOf(GIT_URL)),
            string(name: 'eNB_Branch', value: String.valueOf(env.gitlabSourceBranch)),
            string(name: 'eNB_CommitID', value: String.valueOf(env.gitlabMergeRequestLastCommit)),
            booleanParam(name: 'eNB_mergeRequest', value: "MERGE".equals(env.gitlabActionType)),
            string(name: 'eNB_TargetBranch', value: String.valueOf(env.gitlabTargetBranch))
        ], propagate: false
    localResult = localStatus.getResult()
    echo "${jobName} Slave Job status is ${localResult}"
    if (localStatus.resultIsBetterOrEqualTo('SUCCESS')) {
       echo "${jobName} Slave Job is OK"
810
    } else {
811 812
       echo "${jobName} Slave Job is KO"
       sh "ci-scripts/fail.sh"
813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828
    }
}

def finalizeSlaveJob(jobName) {
    // In case of any non-success, we are retrieving the HTML report of the last completed
    // slave job. The only drop-back is that we may retrieve the HTML report of a previous build
    fileName = "test_results-${jobName}.html"
    if (!fileExists(fileName)) {
        copyArtifacts(projectName: jobName,
            filter: 'test_results*.html',
            selector: lastCompleted())
        if (fileExists(fileName)) {
            sh "sed -i -e 's#TEMPLATE_BUILD_TIME#${JOB_TIMESTAMP}#' ${fileName}"
            archiveArtifacts artifacts: fileName
        }
    }
829
}