Jenkinsfile-gitlab 37.6 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
def doFlexranCtrlTest = false
Raphael Defosseux's avatar
CI:  
Raphael Defosseux committed
34

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

38 39 40
// VM Lockable resources
def vmResource = params.vmLockableResource

41 42 43 44
// Tags to shorten pipeline duration
def doMandatoryTests = false
def doFullTestsuite = false

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

    stages {
Raphael Defosseux's avatar
CI:  
Raphael Defosseux committed
57 58 59
        stage ("Verify Parameters") {
            steps {
                script {
60 61 62
                    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
63 64
                    echo '\u2705 \u001B[32mVerify Parameters\u001B[0m'
                    def allParametersPresent = true
65 66
                    if (env.TESTPLATFORM_OWNER) {
                        echo "Platform is ${env.TESTPLATFORM_OWNER}"
Raphael Defosseux's avatar
Raphael Defosseux committed
67
                    }
Raphael Defosseux's avatar
CI:  
Raphael Defosseux committed
68

69
                    if (params.FlexRanRtcGitLabRepository_Credentials != null) {
Raphael Defosseux's avatar
Raphael Defosseux committed
70
                        doFlexranCtrlTest = true
71 72 73 74
                    }
                    if (fileExists("flexran")) {
                        sh "rm -Rf flexran > /dev/null 2>&1"
                    }
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

                    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
102 103 104
                }
            }
        }
105
        stage ("Verify Guidelines") {
106 107 108 109 110
            steps {
                echo "Git URL         is ${GIT_URL}"
                echo "GitLab Act      is ${env.gitlabActionType}"
                script {
                    if ("MERGE".equals(env.gitlabActionType)) {
111
                        // since a bit, in push events, gitlabUserEmail is not populated
112
                        gitCommitAuthorEmailAddr = env.gitlabUserEmail
113
                        echo "GitLab Usermail is ${gitCommitAuthorEmailAddr}"
114
                        // GitLab-Jenkins plugin integration is lacking to perform the merge by itself
115
                        // Doing it manually --> it may have merge conflicts
116
                        sh "./ci-scripts/doGitLabMerge.sh --src-branch ${env.gitlabSourceBranch} --src-commit ${env.gitlabMergeRequestLastCommit} --target-branch ${env.gitlabTargetBranch} --target-commit ${GIT_COMMIT}"
117
                        sh "zip -r -qq localZip.zip ."
118 119 120 121

                        // 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}"
122 123
                        def res=readFile('./oai_rules_result.txt').trim();
                        if ("0".equals(res)) {
124 125
                            def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): All Changed files in Merge Request follow OAI Formatting Rules"
                            addGitLabMRComment comment: message
126
                        } else {
127 128
                            def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): Some Changed files in Merge Request DO NOT follow OAI Formatting Rules"
                            addGitLabMRComment comment: message
129 130 131 132
                        }
                    } else {
                        echo "Git Branch      is ${GIT_BRANCH}"
                        echo "Git Commit      is ${GIT_COMMIT}"
133 134 135 136
                        // 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}"
137
                        sh "git log -n1 --pretty=format:\"%s\" > .git/CI_COMMIT_MSG"
138

139
                        sh "zip -r -qq localZip.zip ."
140 141
                        // 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
142
                        sh "./ci-scripts/checkCodingFormattingRules.sh"
143
                    }
144
                    if (doFlexranCtrlTest && doMandatoryTests) {
145 146 147 148 149 150
                        sh "mkdir flexran"
                        dir ('flexran') {
                            withCredentials([
                                [$class: 'UsernamePasswordMultiBinding', credentialsId: "${params.FlexRanRtcGitLabRepository_Credentials}", usernameVariable: 'git_username', passwordVariable: 'git_password']
                                ]) {
                                sh "git clone https://${git_username}:${git_password}@gitlab.eurecom.fr/flexran/flexran-rtc.git . > ../git_clone.log 2>&1"
151
                                sh "git checkout develop >> ../git_clone.log 2>&1"
152 153 154 155
                            }
                            sh "zip -r -qq flexran.zip ."
                        }
                    }
156 157
                }
            }
158 159
            post {
                failure {
160 161 162
                    script {
                        def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): Merge Conflicts -- Cannot perform CI"
                        addGitLabMRComment comment: message
Boris Djalal's avatar
Boris Djalal committed
163
                        currentBuild.result = 'FAILURE'
164
                    }
165 166
                }
            }
167
        }
168

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

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

189
        stage ("Start VM -- nr-ue-usrp") {
190
            steps {
191
              lock (vmResource) {
192
                timeout (time: 5, unit: 'MINUTES') {
193
                    sh "./ci-scripts/oai-ci-vm-tool build --workspace $WORKSPACE --variant nr-ue-usrp --job-name ${JOB_NAME} --build-id ${BUILD_ID} --daemon"
194
                }
195
              }
196 197 198
            }
        }

199
        stage ("Start VM -- enb-ethernet") {
200
            steps {
201
              lock (vmResource) {
202
                timeout (time: 7, unit: 'MINUTES') {
203
                    sh "./ci-scripts/oai-ci-vm-tool build --workspace $WORKSPACE --variant enb-ethernet --job-name ${JOB_NAME} --build-id ${BUILD_ID} --daemon"
204
                }
205
              }
206 207 208
            }
        }

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

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

708 709 710 711 712 713
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!',
714
                     to: gitCommitAuthorEmailAddr
715 716 717 718

                if (fileExists('.git/CI_COMMIT_MSG')) {
                    sh "rm -f .git/CI_COMMIT_MSG"
                }
719
            }
720 721 722
        }
        success {
            script {
723
                def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): passed (" + BUILD_URL + ")"
724 725 726
                if ("MERGE".equals(env.gitlabActionType)) {
                    echo "This is a MERGE event"
                    addGitLabMRComment comment: message
727
                    def message2 = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): passed (" + BUILD_URL + ") -- MergeRequest #" + env.gitlabMergeRequestIid + " (" + env.gitlabMergeRequestTitle + ")"
728
                    sendSocialMediaMessage('ci-enb', 'good', message2)
729
                } else {
730
                    sendSocialMediaMessage('ci-enb', 'good', message)
731 732 733 734 735
                }
            }
        }
        failure {
            script {
736
                def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): failed (" + BUILD_URL + ")"
737 738 739
                if ("MERGE".equals(env.gitlabActionType)) {
                    echo "This is a MERGE event"
                    addGitLabMRComment comment: message
740
                    def message2 = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): failed (" + BUILD_URL + ") -- MergeRequest #" + env.gitlabMergeRequestIid + " (" + env.gitlabMergeRequestTitle + ")"
741
                    sendSocialMediaMessage('ci-enb', 'danger', message2)
742
                } else {
743
                    sendSocialMediaMessage('ci-enb', 'danger', message)
744 745 746 747 748
                }
            }
        }
    }
}
749 750 751 752

// ----  Slave Job functions

def triggerSlaveJob (jobName, gitlabStatusName) {
753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772
    // 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"
773 774 775 776 777
        }
    }
}

def triggerSlaveJobNoGitLab (jobName) {
778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793
    // 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"
794
    } else {
795 796
       echo "${jobName} Slave Job is KO"
       sh "ci-scripts/fail.sh"
797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812
    }
}

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
        }
    }
813
}