Jenkinsfile-gitlab 35.9 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
        }
    }
}

Raphael Defosseux's avatar
CI:  
Raphael Defosseux committed
33
def doRedHatBuild = false
34
def doFlexranCtrlTest = false
Raphael Defosseux's avatar
CI:  
Raphael Defosseux committed
35

36 37 38
// Location of the executor node
def nodeExecutor = params.nodeExecutor

39 40
pipeline {
    agent {
41
        label nodeExecutor
42 43 44 45 46
    }
    options {
        disableConcurrentBuilds()
        timestamps()
        gitLabConnection('OAI GitLab')
47
        gitlabBuilds(builds: ["Build eNb-USRP", "Build basic-sim", "Build phy-sim", "Build eNb-ethernet", "Build UE-ethernet", "Analysis with cppcheck", "Test phy-sim", "Test basic-sim", "Test L2-sim", "Test-Mono-FDD-Band7", "Test-Mono-TDD-Band40", "Test-IF4p5-FDD-Band7", "Test-IF4p5-TDD-Band40", "Test-Mono-FDD-Band13", "Test-IF4p5-TDD-Band38-Multi-RRU" , "Test-Mono-FDD-Band13-X2-HO"])
Raphael Defosseux's avatar
CI:  
Raphael Defosseux committed
48
        ansiColor('xterm')
49 50 51
    }

    stages {
Raphael Defosseux's avatar
CI:  
Raphael Defosseux committed
52 53 54
        stage ("Verify Parameters") {
            steps {
                script {
55 56 57
                    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
58 59 60 61 62 63 64 65 66 67 68 69 70
                    echo '\u2705 \u001B[32mVerify Parameters\u001B[0m'
                    def allParametersPresent = true

                    if (params.RedHatRemoteServer == null) {
                        allParametersPresent = false
                    }
                    if (params.RedHatRemoteCredentials == null) {
                        allParametersPresent = false
                    }
                    if (params.RedHatWorkingPath == null) {
                        allParametersPresent = false
                    }
                    if (allParametersPresent) {
71
                        echo "Performing Red Hat Build"
Raphael Defosseux's avatar
CI:  
Raphael Defosseux committed
72 73 74 75
                        doRedHatBuild = true
                    } else {
                        doRedHatBuild = false
                    }
76
                    if (params.FlexRanRtcGitLabRepository_Credentials != null) {
Raphael Defosseux's avatar
Raphael Defosseux committed
77
                        doFlexranCtrlTest = true
78 79 80 81
                    }
                    if (fileExists("flexran")) {
                        sh "rm -Rf flexran > /dev/null 2>&1"
                    }
Raphael Defosseux's avatar
CI:  
Raphael Defosseux committed
82 83 84
                }
            }
        }
85
        stage ("Verify Guidelines") {
86 87 88 89 90
            steps {
                echo "Git URL         is ${GIT_URL}"
                echo "GitLab Act      is ${env.gitlabActionType}"
                script {
                    if ("MERGE".equals(env.gitlabActionType)) {
Raphael Defosseux's avatar
Raphael Defosseux committed
91
                        // since a bit, in push events, gitlabUserEmail is not populated
92
                        gitCommitAuthorEmailAddr = env.gitlabUserEmail
Raphael Defosseux's avatar
Raphael Defosseux committed
93
                        echo "GitLab Usermail is ${gitCommitAuthorEmailAddr}"
94
                        // GitLab-Jenkins plugin integration is lacking to perform the merge by itself
95
                        // Doing it manually --> it may have merge conflicts
96
                        sh "./ci-scripts/doGitLabMerge.sh --src-branch ${env.gitlabSourceBranch} --src-commit ${env.gitlabMergeRequestLastCommit} --target-branch ${env.gitlabTargetBranch} --target-commit ${GIT_COMMIT}"
97
                        sh "zip -r -qq localZip.zip ."
98 99 100 101

                        // 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}"
102 103
                        def res=readFile('./oai_rules_result.txt').trim();
                        if ("0".equals(res)) {
104 105
                            def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): All Changed files in Merge Request follow OAI Formatting Rules"
                            addGitLabMRComment comment: message
106
                        } else {
107 108
                            def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): Some Changed files in Merge Request DO NOT follow OAI Formatting Rules"
                            addGitLabMRComment comment: message
109 110 111 112
                        }
                    } else {
                        echo "Git Branch      is ${GIT_BRANCH}"
                        echo "Git Commit      is ${GIT_COMMIT}"
Raphael Defosseux's avatar
Raphael Defosseux committed
113 114 115 116
                        // 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}"
117
                        sh "git log -n1 --pretty=format:\"%s\" > .git/CI_COMMIT_MSG"
118

119
                        sh "zip -r -qq localZip.zip ."
120 121
                        // 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
122
                        sh "./ci-scripts/checkCodingFormattingRules.sh"
123
                    }
124 125 126 127 128 129 130
                    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"
131
                                sh "git checkout develop >> ../git_clone.log 2>&1"
132 133 134 135
                            }
                            sh "zip -r -qq flexran.zip ."
                        }
                    }
136 137
                }
            }
138 139
            post {
                failure {
140 141 142
                    script {
                        def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): Merge Conflicts -- Cannot perform CI"
                        addGitLabMRComment comment: message
Boris Djalal's avatar
Boris Djalal committed
143
                        currentBuild.result = 'FAILURE'
144
                    }
145 146
                }
            }
147
        }
148

149
        stage ("Start VM -- basic-sim") {
150
            steps {
151
                timeout (time: 5, unit: 'MINUTES') {
152
                    sh "./ci-scripts/oai-ci-vm-tool build --workspace $WORKSPACE --variant basic-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID} --daemon"
153
                }
154 155 156 157 158
            }
        }

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

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

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

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

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

197 198
        stage ("Variant Builds") {
            parallel {
199 200 201
                stage ("Analysis with cppcheck") {
                    steps {
                        gitlabCommitStatus(name: "Analysis with cppcheck") {
202
                            timeout (time: 20, unit: 'MINUTES') {
203
                                sh "./ci-scripts/oai-ci-vm-tool wait --workspace $WORKSPACE --variant cppcheck --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
204
                            }
205 206 207
                        }
                    }
                }
208 209 210
                stage ("Build eNb-USRP") {
                    steps {
                        gitlabCommitStatus(name: "Build eNb-USRP") {
211
                            timeout (time: 20, unit: 'MINUTES') {
212
                                sh "./ci-scripts/oai-ci-vm-tool wait --workspace $WORKSPACE --variant enb-usrp --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
213
                            }
214 215 216 217 218 219
                        }
                    }
                }
                stage ("Build basic simulator") {
                    steps {
                        gitlabCommitStatus(name: "Build basic-sim") {
220
                            timeout (time: 20, unit: 'MINUTES') {
221
                                sh "./ci-scripts/oai-ci-vm-tool wait --workspace $WORKSPACE --variant basic-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep-vm-alive"
222
                            }
223 224
                        }
                    }
225
                }
226
                stage ("Build eNb-ethernet") {
Raphael Defosseux's avatar
Raphael Defosseux committed
227
                    steps {
228
                        gitlabCommitStatus(name: "Build eNb-ethernet") {
229
                            timeout (time: 20, unit: 'MINUTES') {
230
                                sh "./ci-scripts/oai-ci-vm-tool wait --workspace $WORKSPACE --variant enb-ethernet --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep-vm-alive"
231
                            }
Raphael Defosseux's avatar
Raphael Defosseux committed
232 233 234
                        }
                    }
                }
235
                stage ("Build UE-ethernet") {
236
                    steps {
237
                        gitlabCommitStatus(name: "Build UE-ethernet") {
238
                            timeout (time: 20, unit: 'MINUTES') {
239
                                sh "./ci-scripts/oai-ci-vm-tool wait --workspace $WORKSPACE --variant ue-ethernet --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep-vm-alive"
240
                            }
241 242 243
                        }
                    }
                }
244
                stage ("Build physical simulators") {
245
                    steps {
246
                        gitlabCommitStatus(name: "Build phy-sim") {
247
                            timeout (time: 20, unit: 'MINUTES') {
248
                               sh "./ci-scripts/oai-ci-vm-tool wait --workspace $WORKSPACE --variant phy-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep-vm-alive"
249
                            }
250 251 252
                        }
                    }
                }
Raphael Defosseux's avatar
CI:  
Raphael Defosseux committed
253 254 255 256 257
                stage ("Build eNb-USRP on Red Hat") {
                    when {
                        expression {doRedHatBuild}
                    }
                    steps {
258
                        gitlabCommitStatus(name: "Build eNb-USRP-RHE") {
Raphael Defosseux's avatar
Raphael Defosseux committed
259 260 261 262 263
                            script {
                                try {
                                    withCredentials([
                                        [$class: 'UsernamePasswordMultiBinding', credentialsId: "${params.RedHatRemoteCredentials}", usernameVariable: 'RH_Username', passwordVariable: 'RH_Password']
                                    ]) {
264 265 266
                                        timeout (time: 20, unit: 'MINUTES') {
                                            sh "./ci-scripts/buildOnRH.sh --workspace $WORKSPACE --job-name ${JOB_NAME} --build-id ${BUILD_ID} --remote-host ${params.RedHatRemoteServer} --remote-path ${params.RedHatWorkingPath} --remote-user-name ${RH_Username} --remote-password ${RH_Password}"
                                        }
Raphael Defosseux's avatar
Raphael Defosseux committed
267 268
                                    }
                                } catch (Exception e) {
269
                                    echo "Red Hat build failed but we could keep running pipeline if all ubuntu-based build passed"
Raphael Defosseux's avatar
CI:  
Raphael Defosseux committed
270 271 272 273 274
                                }
                            }
                        }
                    }
                }
275 276
            }
            post {
Boris Djalal's avatar
Boris Djalal committed
277 278 279 280 281
                failure {
                    script {
                        currentBuild.result = 'FAILURE'
                    }
                }
282 283
                always {
                    script {
284
                        dir ('archives') {
Raphael Defosseux's avatar
CI:  
Raphael Defosseux committed
285
                            sh "zip -r -qq vm_build_logs.zip basic_sim enb_usrp phy_sim cppcheck enb_eth ue_eth red_hat"
286 287 288
                        }
                        if(fileExists('archives/vm_build_logs.zip')) {
                            archiveArtifacts artifacts: 'archives/vm_build_logs.zip'
289 290
                        }
                        if ("MERGE".equals(env.gitlabActionType)) {
291
                            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}"
292 293 294 295 296 297 298 299 300 301 302
                            // 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
303 304 305 306 307
                            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 {
308
                                def fileList=readFile('./oai_warning_files_list.txt').trim();
Raphael Defosseux's avatar
CI:  
Raphael Defosseux committed
309 310 311
                                def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): Some modified files in Merge Request MAY have INTRODUCED WARNINGS (" + fileList + ")"
                                addGitLabMRComment comment: message
                            }
312
                        } else {
313
                            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}"
314 315
                        }
                        if(fileExists('build_results.html')) {
316
                            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"
317 318 319 320 321 322
                            archiveArtifacts artifacts: 'build_results.html'
                        }
                    }
                }
            }
        }
Raphael Defosseux's avatar
Raphael Defosseux committed
323

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

635 636 637
Here are attached HTML report files for $PROJECT_NAME - Build # $BUILD_NUMBER - $BUILD_STATUS!

Regards,
Raphael Defosseux's avatar
Raphael Defosseux committed
638
OAI CI Team''',
639 640
                     replyTo: 'no-reply@openairinterface.org',
                     subject: '$PROJECT_NAME - Build # $BUILD_NUMBER - $BUILD_STATUS!',
Raphael Defosseux's avatar
Raphael Defosseux committed
641
                     to: gitCommitAuthorEmailAddr
642 643 644 645

                if (fileExists('.git/CI_COMMIT_MSG')) {
                    sh "rm -f .git/CI_COMMIT_MSG"
                }
646
            }
647 648 649
        }
        success {
            script {
650
                def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): passed (" + BUILD_URL + ")"
651 652 653
                if ("MERGE".equals(env.gitlabActionType)) {
                    echo "This is a MERGE event"
                    addGitLabMRComment comment: message
654
                    def message2 = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): passed (" + BUILD_URL + ") -- MergeRequest #" + env.gitlabMergeRequestIid + " (" + env.gitlabMergeRequestTitle + ")"
655
                    sendSocialMediaMessage('ci-enb', 'good', message2)
656
                } else {
657
                    sendSocialMediaMessage('ci-enb', 'good', message)
658 659 660 661 662
                }
            }
        }
        failure {
            script {
663
                def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): failed (" + BUILD_URL + ")"
664 665 666
                if ("MERGE".equals(env.gitlabActionType)) {
                    echo "This is a MERGE event"
                    addGitLabMRComment comment: message
667
                    def message2 = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): failed (" + BUILD_URL + ") -- MergeRequest #" + env.gitlabMergeRequestIid + " (" + env.gitlabMergeRequestTitle + ")"
668
                    sendSocialMediaMessage('ci-enb', 'danger', message2)
669
                } else {
670
                    sendSocialMediaMessage('ci-enb', 'danger', message)
671 672 673 674 675
                }
            }
        }
    }
}
676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738

// ----  Slave Job functions

def triggerSlaveJob (jobName, gitlabStatusName) {
    if ("MERGE".equals(env.gitlabActionType)) {
        gitlabCommitStatus(name: gitlabStatusName) {
            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: true),
                    string(name: 'eNB_TargetBranch', value: String.valueOf(env.gitlabTargetBranch))
                ]
        }
    } else {
        gitlabCommitStatus(name: gitlabStatusName) {
            build job: jobName,
                parameters: [
                    string(name: 'eNB_Repository', value: String.valueOf(GIT_URL)),
                    string(name: 'eNB_Branch', value: String.valueOf(GIT_BRANCH)),
                    string(name: 'eNB_CommitID', value: String.valueOf(GIT_COMMIT)),
                    booleanParam(name: 'eNB_mergeRequest', value: false)
                ]
       }
    }
}

def triggerSlaveJobNoGitLab (jobName) {
    if ("MERGE".equals(env.gitlabActionType)) {
        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: true),
                string(name: 'eNB_TargetBranch', value: String.valueOf(env.gitlabTargetBranch))
            ]
    } else {
        build job: jobName,
            parameters: [
                string(name: 'eNB_Repository', value: String.valueOf(GIT_URL)),
                string(name: 'eNB_Branch', value: String.valueOf(GIT_BRANCH)),
                string(name: 'eNB_CommitID', value: String.valueOf(GIT_COMMIT)),
                booleanParam(name: 'eNB_mergeRequest', value: false)
            ]
    }
}

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