Jenkinsfile-gitlab 39.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 401
                                    }
                                }
                              }
                            }
                        }
                        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'
                                        }
402 403
                                    }
                                }
404
                              }
405 406
                            }
                        }
407
                        stage ("Test L2 simulator") {
408 409 410
                            when {
                                expression {doFullTestsuite}
                            }
411
                            steps {
412
                              lock (vmResource) {
413
                                script {
Raphael Defosseux's avatar
Raphael Defosseux committed
414 415 416
                                    timeout (time: 30, unit: 'MINUTES') {
                                        try {
                                            gitlabCommitStatus(name: "Test L2-sim") {
417 418
                                                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
419 420
                                        } catch (Exception e) {
                                            currentBuild.result = 'FAILURE'
421
                                        }
422 423
                                    }
                                }
424
                              }
425
                            }
426
                        }
427
                        stage ("Destroy all Virtual Machines") {
428 429 430
                            when {
                                expression {doMandatoryTests}
                            }
431
                            steps {
432
                              lock (vmResource) {
433
                                sh "./ci-scripts/oai-ci-vm-tool destroy --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
434
                              }
435
                            }
436
                        }
Raphael Defosseux's avatar
Raphael Defosseux committed
437 438
                    }
                }
439
                stage ("Test MONOLITHIC - FDD - Band 7 - B210") {
440 441 442
                    when {
                        expression {doFullTestsuite}
                    }
Raphael Defosseux's avatar
Raphael Defosseux committed
443
                    steps {
444
                        script {
445
                            triggerSlaveJob ('eNB-CI-FDD-Band7-B210', 'Test-Mono-FDD-Band7')
446 447 448 449 450
                        }
                    }
                    post {
                        always {
                            script {
451
                                finalizeSlaveJob('eNB-CI-FDD-Band7-B210')
452 453
                            }
                        }
454 455 456
                        failure {
                            script {
                                currentBuild.result = 'FAILURE'
457
                            }
458
                        }
Raphael Defosseux's avatar
Raphael Defosseux committed
459 460
                    }
                }
461
                stage ("Test MONOLITHIC - TDD - Band 40 - B210") {
462 463 464
                    when {
                        expression {doFullTestsuite}
                    }
465 466
                    steps {
                        script {
467
                            triggerSlaveJob ('eNB-CI-TDD-Band40-B210', 'Test-Mono-TDD-Band40')
468 469 470 471 472
                        }
                    }
                    post {
                        always {
                            script {
473
                                finalizeSlaveJob('eNB-CI-TDD-Band40-B210')
474 475
                            }
                        }
476 477 478
                        failure {
                            script {
                                currentBuild.result = 'FAILURE'
479 480
                            }
                        }
481 482
                    }
                }
483
                stage ("Test IF4p5 - FDD - Band 7 - B210") {
484 485 486
                    when {
                        expression {doFullTestsuite}
                    }
487 488
                    steps {
                        script {
Raphael Defosseux's avatar
Raphael Defosseux committed
489
                            sh "sleep 60"
490
                            triggerSlaveJob ('eNB-CI-IF4p5-FDD-Band7-B210', 'Test-IF4p5-FDD-Band7')
491 492 493 494 495
                        }
                    }
                    post {
                        always {
                            script {
496
                                finalizeSlaveJob('eNB-CI-IF4p5-FDD-Band7-B210')
497 498
                            }
                        }
499
                        failure {
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522
                            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 {
523 524
                            script {
                                currentBuild.result = 'FAILURE'
525 526
                            }
                        }
527 528
                    }
                }
529
                stage ("Test IF4p5 - TDD - Band 40 - B210") {
530 531 532
                    when {
                        expression {doFullTestsuite}
                    }
533 534
                    steps {
                        script {
Raphael Defosseux's avatar
Raphael Defosseux committed
535
                            sh "sleep 60"
536
                            triggerSlaveJob ('eNB-CI-IF4p5-TDD-Band40-B210', 'Test-IF4p5-TDD-Band40')
537 538 539 540 541
                        }
                    }
                    post {
                        always {
                            script {
542
                                finalizeSlaveJob('eNB-CI-IF4p5-TDD-Band40-B210')
Raphael Defosseux's avatar
CI:  
Raphael Defosseux committed
543 544
                            }
                        }
545 546 547
                        failure {
                            script {
                                currentBuild.result = 'FAILURE'
548
                            }
549 550
                        }
                    }
551
                }
552
                stage ("Test MONOLITHIC - FDD - Band 13 - B210") {
553 554 555
                    when {
                        expression {doFullTestsuite}
                    }
556 557
                    steps {
                        script {
Raphael Defosseux's avatar
Raphael Defosseux committed
558
                            sh "sleep 60"
559
                            triggerSlaveJob ('eNB-CI-MONO-FDD-Band13-B210', 'Test-Mono-FDD-Band13-LTE-M')
560 561
                        }
                    }
562 563 564
                    post {
                        always {
                            script {
565
                                finalizeSlaveJob('eNB-CI-MONO-FDD-Band13-B210')
566 567 568 569 570
                            }
                        }
                        failure {
                            script {
                                currentBuild.result = 'FAILURE'
571 572
                            }
                        }
573 574
                    }
                }
575
                stage ("Test X2 Handover - FDD - Band 13 - B210") {
576 577 578
                    when {
                        expression {doFullTestsuite}
                    }
579 580
                    steps {
                        script {
581
                            sh "sleep 60"
582
                            triggerSlaveJob ('eNB-CI-MONO-FDD-Band13-X2HO-B210', 'Test-Mono-FDD-Band13-X2-HO')
583 584 585 586 587
                        }
                    }
                    post {
                        always {
                            script {
588
                                finalizeSlaveJob('eNB-CI-MONO-FDD-Band13-X2HO-B210')
589 590 591 592 593
                            }
                        }
                        failure {
                            script {
                                currentBuild.result = 'FAILURE'
594 595 596 597 598
                            }
                        }
                    }
                }
                stage ("Test IF4p5 - TDD - Band 38 - B210 - MultiRRU") {
599 600 601
                    when {
                        expression {doFullTestsuite}
                    }
602 603 604 605 606 607 608 609 610 611 612 613 614 615
                    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'
616 617 618 619
                            }
                        }
                    }
                }
Raphael Defosseux's avatar
Raphael Defosseux committed
620
                stage ("Test OAI UE - FDD - Band 20 - B200") {
621 622 623
                    when {
                        expression {doFullTestsuite}
                    }
624 625
                    steps {
                        script {
626
                            triggerSlaveJobNoGitLab ('UE-CI-FDD-Band20-B200')
627 628 629 630 631
                        }
                    }
                    post {
                        always {
                            script {
632
                                finalizeSlaveJob('UE-CI-FDD-Band20-B200')
Raphael Defosseux's avatar
Raphael Defosseux committed
633 634 635 636 637
                            }
                        }
                        failure {
                            script {
                                currentBuild.result = 'FAILURE'
638
                            }
639 640
                        }
                    }
Raphael Defosseux's avatar
Raphael Defosseux committed
641 642
                }
                stage ("Test OAI UE - OAI eNB - FDD - Band 7 - B200") {
643 644 645
                    when {
                        expression {doFullTestsuite}
                    }
Raphael Defosseux's avatar
Raphael Defosseux committed
646 647 648 649 650 651 652
                    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')
                        }
                    }
653 654 655
                    post {
                        always {
                            script {
656
                                finalizeSlaveJob('eNB-UE-CI-MONO-FDD-Band7-B200')
657 658 659 660 661
                            }
                        }
                        failure {
                            script {
                                currentBuild.result = 'FAILURE'
662 663
                            }
                        }
664
                    }
665
                }
666
                stage ("Test OAI NR UE - OAI gNB - TDD - Band 78 - N300") {
667 668 669
                    when {
                        expression {doMandatoryTests}
                    }
670 671 672 673 674 675 676 677 678 679 680 681 682 683
                    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'
684 685 686 687 688
                            }
                        }
                    }
                }
                stage ("Test OAI OCP-eNB - FDD - Band 7 - B210") {
689 690 691
                    when {
                        expression {doFullTestsuite}
                    }
692 693 694 695 696 697 698 699 700 701 702 703 704 705
                    steps {
                        script {
                            triggerSlaveJob ('OCPeNB-FDD-Band7-B210', 'Test-OCP-FDD-Band7')
                        }
                    }
                    post {
                        always {
                            script {
                                finalizeSlaveJob('OCPeNB-FDD-Band7-B210')
                            }
                        }
                        failure {
                            script {
                                currentBuild.result = 'FAILURE'
706 707 708 709
                            }
                        }
                    }
                }
Raphael Defosseux's avatar
Raphael Defosseux committed
710 711 712 713
            }
            post {
                always {
                    script {
714
                      if (doMandatoryTests) {
Raphael Defosseux's avatar
Raphael Defosseux committed
715
                        dir ('archives') {
716
                            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
717 718 719
                        }
                        if(fileExists('archives/vm_tests_logs.zip')) {
                            archiveArtifacts artifacts: 'archives/vm_tests_logs.zip'
720
                            if ("MERGE".equals(env.gitlabActionType)) {
721
                                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}"
722
                            } else {
723
                                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}"
724 725
                            }
                            if(fileExists('test_simulator_results.html')) {
726
                                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"
727 728
                                archiveArtifacts artifacts: 'test_simulator_results.html'
                            }
Raphael Defosseux's avatar
Raphael Defosseux committed
729
                        }
730
                      }
Raphael Defosseux's avatar
Raphael Defosseux committed
731 732 733 734
                    }
                }
            }
        }
735 736 737
    }
    post {
        always {
738
            script {
Raphael Defosseux's avatar
Raphael Defosseux committed
739
                // Stage destroy may not be run if error in previous stage
740
                sh "./ci-scripts/oai-ci-vm-tool destroy --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
741 742
                emailext attachmentsPattern: '*results*.html',
                     body: '''Hi,
743

744 745 746 747 748 749
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!',
750
                     to: gitCommitAuthorEmailAddr
751 752 753 754

                if (fileExists('.git/CI_COMMIT_MSG')) {
                    sh "rm -f .git/CI_COMMIT_MSG"
                }
755
            }
756 757 758
        }
        success {
            script {
759
                def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): passed (" + BUILD_URL + ")"
760 761 762
                if ("MERGE".equals(env.gitlabActionType)) {
                    echo "This is a MERGE event"
                    addGitLabMRComment comment: message
763
                    def message2 = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): passed (" + BUILD_URL + ") -- MergeRequest #" + env.gitlabMergeRequestIid + " (" + env.gitlabMergeRequestTitle + ")"
764
                    sendSocialMediaMessage('ci-enb', 'good', message2)
765
                } else {
766
                    sendSocialMediaMessage('ci-enb', 'good', message)
767 768 769 770 771
                }
            }
        }
        failure {
            script {
772
                def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): failed (" + BUILD_URL + ")"
773 774 775
                if ("MERGE".equals(env.gitlabActionType)) {
                    echo "This is a MERGE event"
                    addGitLabMRComment comment: message
776
                    def message2 = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): failed (" + BUILD_URL + ") -- MergeRequest #" + env.gitlabMergeRequestIid + " (" + env.gitlabMergeRequestTitle + ")"
777
                    sendSocialMediaMessage('ci-enb', 'danger', message2)
778
                } else {
779
                    sendSocialMediaMessage('ci-enb', 'danger', message)
780 781 782 783 784
                }
            }
        }
    }
}
785 786 787 788

// ----  Slave Job functions

def triggerSlaveJob (jobName, gitlabStatusName) {
789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808
    // 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"
809 810 811 812 813
        }
    }
}

def triggerSlaveJobNoGitLab (jobName) {
814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829
    // 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"
830
    } else {
831 832
       echo "${jobName} Slave Job is KO"
       sh "ci-scripts/fail.sh"
833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848
    }
}

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