Jenkinsfile-gitlab 38 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
pipeline {
    agent {
40
        label nodeExecutor
41 42 43 44 45
    }
    options {
        disableConcurrentBuilds()
        timestamps()
        gitLabConnection('OAI GitLab')
46 47 48 49 50 51 52 53 54 55 56
        gitlabBuilds(builds: [
            "Build gNB-USRP",
            "Build nr-UE-USRP",
            "Build eNB-USRP",
            "Build basic-sim",
            "Build phy-sim",
            "Build eNB-ethernet",
            "Build UE-ethernet",
            "Analysis with cppcheck",
            "Test phy-sim",
            "Test basic-sim",
57 58
            "Test L1-sim",
            "Test RF-sim",
59 60 61 62 63 64 65 66 67
            "Test L2-sim",
            "Test-Mono-FDD-Band7",
            "Test-Mono-TDD-Band40",
            "Test-IF4p5-FDD-Band7",
            "Test-IF4p5-TDD-Band40",
            "Test-Mono-FDD-Band13-LTE-M",
            "Test-IF4p5-TDD-Band38-Multi-RRU",
            "Test-eNB-OAI-UE-FDD-Band7",
            "Test-Mono-FDD-Band13-X2-HO",
68 69
            "Test-TDD-Band78-gNB-NR-UE",
            "Test-OCP-FDD-Band7"
70
        ])
Raphael Defosseux's avatar
CI:  
Raphael Defosseux committed
71
        ansiColor('xterm')
72 73 74
    }

    stages {
Raphael Defosseux's avatar
CI:  
Raphael Defosseux committed
75 76 77
        stage ("Verify Parameters") {
            steps {
                script {
78 79 80
                    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
81 82
                    echo '\u2705 \u001B[32mVerify Parameters\u001B[0m'
                    def allParametersPresent = true
83 84
                    if (env.TESTPLATFORM_OWNER) {
                        echo "Platform is ${env.TESTPLATFORM_OWNER}"
Raphael Defosseux's avatar
Raphael Defosseux committed
85
                    }
Raphael Defosseux's avatar
CI:  
Raphael Defosseux committed
86

87
                    if (params.FlexRanRtcGitLabRepository_Credentials != null) {
Raphael Defosseux's avatar
Raphael Defosseux committed
88
                        doFlexranCtrlTest = true
89 90 91 92
                    }
                    if (fileExists("flexran")) {
                        sh "rm -Rf flexran > /dev/null 2>&1"
                    }
Raphael Defosseux's avatar
CI:  
Raphael Defosseux committed
93 94 95
                }
            }
        }
96
        stage ("Verify Guidelines") {
97 98 99 100 101
            steps {
                echo "Git URL         is ${GIT_URL}"
                echo "GitLab Act      is ${env.gitlabActionType}"
                script {
                    if ("MERGE".equals(env.gitlabActionType)) {
102
                        // since a bit, in push events, gitlabUserEmail is not populated
103
                        gitCommitAuthorEmailAddr = env.gitlabUserEmail
104
                        echo "GitLab Usermail is ${gitCommitAuthorEmailAddr}"
105
                        // GitLab-Jenkins plugin integration is lacking to perform the merge by itself
106
                        // Doing it manually --> it may have merge conflicts
107
                        sh "./ci-scripts/doGitLabMerge.sh --src-branch ${env.gitlabSourceBranch} --src-commit ${env.gitlabMergeRequestLastCommit} --target-branch ${env.gitlabTargetBranch} --target-commit ${GIT_COMMIT}"
108
                        sh "zip -r -qq localZip.zip ."
109 110 111 112

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

130
                        sh "zip -r -qq localZip.zip ."
131 132
                        // 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
133
                        sh "./ci-scripts/checkCodingFormattingRules.sh"
134
                    }
135 136 137 138 139 140 141
                    if (doFlexranCtrlTest) {
                        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"
142
                                sh "git checkout develop >> ../git_clone.log 2>&1"
143 144 145 146
                            }
                            sh "zip -r -qq flexran.zip ."
                        }
                    }
147 148
                }
            }
149 150
            post {
                failure {
151 152 153
                    script {
                        def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): Merge Conflicts -- Cannot perform CI"
                        addGitLabMRComment comment: message
Boris Djalal's avatar
Boris Djalal committed
154
                        currentBuild.result = 'FAILURE'
155
                    }
156 157
                }
            }
158
        }
159

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

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

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

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

192
        stage ("Start VM -- phy-sim") {
193
            steps {
194
                timeout (time: 5, unit: 'MINUTES') {
195
                    sh "./ci-scripts/oai-ci-vm-tool build --workspace $WORKSPACE --variant phy-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID} --daemon"
196
                }
197 198
            }
        }
199 200
        
        stage ("Start VM -- enb-ethernet") {
201
            steps {
202
                timeout (time: 5, 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
        stage ("Start VM -- ue-ethernet") {
209
            steps {
210
                timeout (time: 5, unit: 'MINUTES') {
211
                    sh "./ci-scripts/oai-ci-vm-tool build --workspace $WORKSPACE --variant ue-ethernet --job-name ${JOB_NAME} --build-id ${BUILD_ID} --daemon"
212
                }
213 214
            }
        }
215
        
216
        stage ("Start VM -- cppcheck") {
217
            steps {
218
                timeout (time: 5, unit: 'MINUTES') {
219
                    sh "./ci-scripts/oai-ci-vm-tool build --workspace $WORKSPACE --variant cppcheck --job-name ${JOB_NAME} --build-id ${BUILD_ID} --daemon"
220
                }
221 222 223
            }
        }

224 225
        stage ("Variant Builds") {
            parallel {
226 227 228
                stage ("Analysis with cppcheck") {
                    steps {
                        gitlabCommitStatus(name: "Analysis with cppcheck") {
229
                            timeout (time: 20, unit: 'MINUTES') {
230
                                sh "./ci-scripts/oai-ci-vm-tool wait --workspace $WORKSPACE --variant cppcheck --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
231
                            }
232 233 234
                        }
                    }
                }
235
                stage ("Build basic simulator") {
236
                    steps {
237
                        gitlabCommitStatus(name: "Build basic-sim") {
238
                            timeout (time: 20, unit: 'MINUTES') {
239
                                sh "./ci-scripts/oai-ci-vm-tool wait --workspace $WORKSPACE --variant basic-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep-vm-alive"
240
                            }
241 242 243
                        }
                    }
                }
244
                stage ("Build 5G gNB-USRP") {
245
                    steps {
246
                        gitlabCommitStatus(name: "Build gNB-USRP") {
247
                            timeout (time: 20, unit: 'MINUTES') {
248
                                sh "./ci-scripts/oai-ci-vm-tool wait --workspace $WORKSPACE --variant gnb-usrp --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep-vm-alive"
249
                            }
250 251
                        }
                    }
252
                }
253
                stage ("Build 5G NR-UE-USRP") {
254
                    steps {
255
                        gitlabCommitStatus(name: "Build nr-UE-USRP") {
256
                            timeout (time: 20, unit: 'MINUTES') {
257
                                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"
258
                            }
259 260 261
                        }
                    }
                }
262
                stage ("Build eNB-USRP") {
263
                    steps {
264
                        gitlabCommitStatus(name: "Build eNB-USRP") {
265
                            timeout (time: 20, unit: 'MINUTES') {
266
                                sh "./ci-scripts/oai-ci-vm-tool wait --workspace $WORKSPACE --variant enb-usrp --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
267
                            }
268 269 270
                        }
                    }
                }
271
                stage ("Build physical simulators") {
Raphael Defosseux's avatar
Raphael Defosseux committed
272
                    steps {
273
                        gitlabCommitStatus(name: "Build phy-sim") {
274
                            timeout (time: 20, unit: 'MINUTES') {
275
                               sh "./ci-scripts/oai-ci-vm-tool wait --workspace $WORKSPACE --variant phy-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep-vm-alive"
276
                            }
Raphael Defosseux's avatar
Raphael Defosseux committed
277 278 279
                        }
                    }
                }
280
                stage ("Build eNB-ethernet") {
281
                    steps {
282
                        gitlabCommitStatus(name: "Build eNB-ethernet") {
283
                            timeout (time: 20, unit: 'MINUTES') {
284
                                sh "./ci-scripts/oai-ci-vm-tool wait --workspace $WORKSPACE --variant enb-ethernet --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep-vm-alive"
285
                            }
286 287 288
                        }
                    }
                }
289
                stage ("Build UE-ethernet") {
290
                    steps {
291
                        gitlabCommitStatus(name: "Build UE-ethernet") {
292
                            timeout (time: 20, unit: 'MINUTES') {
293
                                sh "./ci-scripts/oai-ci-vm-tool wait --workspace $WORKSPACE --variant ue-ethernet --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep-vm-alive"
294
                            }
295 296 297
                        }
                    }
                }
298 299
            }
            post {
Boris Djalal's avatar
Boris Djalal committed
300 301 302 303 304
                failure {
                    script {
                        currentBuild.result = 'FAILURE'
                    }
                }
305 306
                always {
                    script {
307
                        dir ('archives') {
308 309 310 311 312
                            if (fileExists('red_hat')) {
                                sh "zip -r -qq vm_build_logs.zip basic_sim enb_usrp phy_sim cppcheck enb_eth ue_eth gnb_usrp nr_ue_usrp red_hat"
                            } else {
                                sh "zip -r -qq vm_build_logs.zip basic_sim enb_usrp phy_sim cppcheck enb_eth ue_eth gnb_usrp nr_ue_usrp"
                            }
313 314 315
                        }
                        if(fileExists('archives/vm_build_logs.zip')) {
                            archiveArtifacts artifacts: 'archives/vm_build_logs.zip'
316 317
                        }
                        if ("MERGE".equals(env.gitlabActionType)) {
318
                            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}"
319 320 321 322 323 324 325 326 327 328 329
                            // If the merge request has introduced more CPPCHECK errors or warnings, notifications in GitLab
                            if (fileExists('oai_cppcheck_added_errors.txt')) {
                                def ret=readFile('./oai_cppcheck_added_errors.txt').trim();
                                if ("0".equals(ret)) {
                                    echo "No added cppcheck warnings/errors in this merge request"
                                } else {
                                    def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): Some modified files in Merge Request MAY have INTRODUCED up to " + ret + " CPPCHECK errors/warnings"
                                    addGitLabMRComment comment: message
                                }
                            }
                            // If the merge request has introduced compilation warnings, notifications in GitLab
Raphael Defosseux's avatar
CI:  
Raphael Defosseux committed
330 331 332 333 334
                            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 {
335
                                def fileList=readFile('./oai_warning_files_list.txt').trim();
Raphael Defosseux's avatar
CI:  
Raphael Defosseux committed
336 337 338
                                def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): Some modified files in Merge Request MAY have INTRODUCED WARNINGS (" + fileList + ")"
                                addGitLabMRComment comment: message
                            }
339
                        } else {
340
                            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}"
341 342
                        }
                        if(fileExists('build_results.html')) {
343
                            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"
344 345 346 347 348 349
                            archiveArtifacts artifacts: 'build_results.html'
                        }
                    }
                }
            }
        }
Raphael Defosseux's avatar
Raphael Defosseux committed
350

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

700 701 702 703 704 705
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!',
706
                     to: gitCommitAuthorEmailAddr
707 708 709 710

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

// ----  Slave Job functions

def triggerSlaveJob (jobName, gitlabStatusName) {
745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764
    // 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"
765 766 767 768 769
        }
    }
}

def triggerSlaveJobNoGitLab (jobName) {
770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785
    // 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"
786
    } else {
787 788
       echo "${jobName} Slave Job is KO"
       sh "ci-scripts/fail.sh"
789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804
    }
}

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