Jenkinsfile-gitlab 39.3 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
// Location of the executor node
def nodeExecutor = params.nodeExecutor
Raphael Defosseux's avatar
CI:  
Raphael Defosseux committed
38

39 40
pipeline {
    agent {
41
        label nodeExecutor
42 43 44 45 46
    }
    options {
        disableConcurrentBuilds()
        timestamps()
        gitLabConnection('OAI GitLab')
47 48 49 50 51 52 53 54 55 56 57
        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",
58 59
            "Test L1-sim",
            "Test RF-sim",
60 61 62 63 64 65 66 67 68 69 70
            "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",
            "Test-TDD-Band78-gNB-NR-UE"
        ])
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 88 89 90 91 92 93 94 95 96

                    if (params.RedHatRemoteServer == null) {
                        allParametersPresent = false
                    }
                    if (params.RedHatRemoteCredentials == null) {
                        allParametersPresent = false
                    }
                    if (params.RedHatWorkingPath == null) {
                        allParametersPresent = false
                    }
                    if (allParametersPresent) {
97
                        echo "Performing Red Hat Build"
Raphael Defosseux's avatar
CI:  
Raphael Defosseux committed
98 99 100 101
                        doRedHatBuild = true
                    } else {
                        doRedHatBuild = false
                    }
102
                    if (params.FlexRanRtcGitLabRepository_Credentials != null) {
Raphael Defosseux's avatar
Raphael Defosseux committed
103
                        doFlexranCtrlTest = true
104 105 106 107
                    }
                    if (fileExists("flexran")) {
                        sh "rm -Rf flexran > /dev/null 2>&1"
                    }
Raphael Defosseux's avatar
CI:  
Raphael Defosseux committed
108 109 110
                }
            }
        }
111
        stage ("Verify Guidelines") {
112 113 114 115 116
            steps {
                echo "Git URL         is ${GIT_URL}"
                echo "GitLab Act      is ${env.gitlabActionType}"
                script {
                    if ("MERGE".equals(env.gitlabActionType)) {
117
                        // since a bit, in push events, gitlabUserEmail is not populated
118
                        gitCommitAuthorEmailAddr = env.gitlabUserEmail
119
                        echo "GitLab Usermail is ${gitCommitAuthorEmailAddr}"
120
                        // GitLab-Jenkins plugin integration is lacking to perform the merge by itself
121
                        // Doing it manually --> it may have merge conflicts
122
                        sh "./ci-scripts/doGitLabMerge.sh --src-branch ${env.gitlabSourceBranch} --src-commit ${env.gitlabMergeRequestLastCommit} --target-branch ${env.gitlabTargetBranch} --target-commit ${GIT_COMMIT}"
123
                        sh "zip -r -qq localZip.zip ."
124 125 126 127

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

145
                        sh "zip -r -qq localZip.zip ."
146 147
                        // 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
148
                        sh "./ci-scripts/checkCodingFormattingRules.sh"
149
                    }
150 151 152 153 154 155 156
                    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"
157
                                sh "git checkout develop >> ../git_clone.log 2>&1"
158 159 160 161
                            }
                            sh "zip -r -qq flexran.zip ."
                        }
                    }
162 163
                }
            }
164 165
            post {
                failure {
166 167 168
                    script {
                        def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): Merge Conflicts -- Cannot perform CI"
                        addGitLabMRComment comment: message
Boris Djalal's avatar
Boris Djalal committed
169
                        currentBuild.result = 'FAILURE'
170
                    }
171 172
                }
            }
173
        }
174

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

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

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

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

207
        stage ("Start VM -- phy-sim") {
208
            steps {
209
                timeout (time: 5, unit: 'MINUTES') {
210
                    sh "./ci-scripts/oai-ci-vm-tool build --workspace $WORKSPACE --variant phy-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID} --daemon"
211
                }
212 213
            }
        }
214 215
        
        stage ("Start VM -- enb-ethernet") {
216
            steps {
217
                timeout (time: 5, unit: 'MINUTES') {
218
                    sh "./ci-scripts/oai-ci-vm-tool build --workspace $WORKSPACE --variant enb-ethernet --job-name ${JOB_NAME} --build-id ${BUILD_ID} --daemon"
219
                }
220 221 222
            }
        }

223
        stage ("Start VM -- ue-ethernet") {
224
            steps {
225
                timeout (time: 5, unit: 'MINUTES') {
226
                    sh "./ci-scripts/oai-ci-vm-tool build --workspace $WORKSPACE --variant ue-ethernet --job-name ${JOB_NAME} --build-id ${BUILD_ID} --daemon"
227
                }
228 229
            }
        }
230
        
231
        stage ("Start VM -- cppcheck") {
232
            steps {
233
                timeout (time: 5, unit: 'MINUTES') {
234
                    sh "./ci-scripts/oai-ci-vm-tool build --workspace $WORKSPACE --variant cppcheck --job-name ${JOB_NAME} --build-id ${BUILD_ID} --daemon"
235
                }
236 237 238
            }
        }

239 240
        stage ("Variant Builds") {
            parallel {
241 242 243
                stage ("Analysis with cppcheck") {
                    steps {
                        gitlabCommitStatus(name: "Analysis with cppcheck") {
244
                            timeout (time: 20, unit: 'MINUTES') {
245
                                sh "./ci-scripts/oai-ci-vm-tool wait --workspace $WORKSPACE --variant cppcheck --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
246
                            }
247 248 249
                        }
                    }
                }
250
                stage ("Build basic simulator") {
251
                    steps {
252
                        gitlabCommitStatus(name: "Build basic-sim") {
253
                            timeout (time: 20, unit: 'MINUTES') {
254
                                sh "./ci-scripts/oai-ci-vm-tool wait --workspace $WORKSPACE --variant basic-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep-vm-alive"
255
                            }
256 257 258
                        }
                    }
                }
259
                stage ("Build 5G gNB-USRP") {
260
                    steps {
261
                        gitlabCommitStatus(name: "Build gNB-USRP") {
262
                            timeout (time: 20, unit: 'MINUTES') {
263
                                sh "./ci-scripts/oai-ci-vm-tool wait --workspace $WORKSPACE --variant gnb-usrp --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep-vm-alive"
264
                            }
265 266
                        }
                    }
267
                }
268
                stage ("Build 5G NR-UE-USRP") {
269
                    steps {
270
                        gitlabCommitStatus(name: "Build nr-UE-USRP") {
271
                            timeout (time: 20, unit: 'MINUTES') {
272
                                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"
273
                            }
274 275 276
                        }
                    }
                }
277
                stage ("Build eNB-USRP") {
278
                    steps {
279
                        gitlabCommitStatus(name: "Build eNB-USRP") {
280
                            timeout (time: 20, unit: 'MINUTES') {
281
                                sh "./ci-scripts/oai-ci-vm-tool wait --workspace $WORKSPACE --variant enb-usrp --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep-vm-alive"
282
                            }
283 284 285
                        }
                    }
                }
286
                stage ("Build physical simulators") {
Raphael Defosseux's avatar
Raphael Defosseux committed
287
                    steps {
288
                        gitlabCommitStatus(name: "Build phy-sim") {
289
                            timeout (time: 20, unit: 'MINUTES') {
290
                               sh "./ci-scripts/oai-ci-vm-tool wait --workspace $WORKSPACE --variant phy-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep-vm-alive"
291
                            }
Raphael Defosseux's avatar
Raphael Defosseux committed
292 293 294
                        }
                    }
                }
295
                stage ("Build eNB-ethernet") {
296
                    steps {
297
                        gitlabCommitStatus(name: "Build eNB-ethernet") {
298
                            timeout (time: 20, unit: 'MINUTES') {
299
                                sh "./ci-scripts/oai-ci-vm-tool wait --workspace $WORKSPACE --variant enb-ethernet --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep-vm-alive"
300
                            }
301 302 303
                        }
                    }
                }
304
                stage ("Build UE-ethernet") {
305
                    steps {
306
                        gitlabCommitStatus(name: "Build UE-ethernet") {
307
                            timeout (time: 20, unit: 'MINUTES') {
308
                                sh "./ci-scripts/oai-ci-vm-tool wait --workspace $WORKSPACE --variant ue-ethernet --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep-vm-alive"
309
                            }
310 311 312
                        }
                    }
                }
313
                stage ("Build eNB-USRP on Red Hat") {
Raphael Defosseux's avatar
CI:  
Raphael Defosseux committed
314 315 316 317
                    when {
                        expression {doRedHatBuild}
                    }
                    steps {
318
                        gitlabCommitStatus(name: "Build eNB-USRP-RHE") {
Raphael Defosseux's avatar
Raphael Defosseux committed
319 320 321 322 323
                            script {
                                try {
                                    withCredentials([
                                        [$class: 'UsernamePasswordMultiBinding', credentialsId: "${params.RedHatRemoteCredentials}", usernameVariable: 'RH_Username', passwordVariable: 'RH_Password']
                                    ]) {
324 325 326
                                        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
327 328
                                    }
                                } catch (Exception e) {
329
                                    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
330 331 332 333 334
                                }
                            }
                        }
                    }
                }
335 336
            }
            post {
Boris Djalal's avatar
Boris Djalal committed
337 338 339 340 341
                failure {
                    script {
                        currentBuild.result = 'FAILURE'
                    }
                }
342 343
                always {
                    script {
344
                        dir ('archives') {
345 346 347 348 349
                            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"
                            }
350 351 352
                        }
                        if(fileExists('archives/vm_build_logs.zip')) {
                            archiveArtifacts artifacts: 'archives/vm_build_logs.zip'
353 354
                        }
                        if ("MERGE".equals(env.gitlabActionType)) {
355
                            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}"
356 357 358 359 360 361 362 363 364 365 366
                            // 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
367 368 369 370 371
                            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 {
372
                                def fileList=readFile('./oai_warning_files_list.txt').trim();
Raphael Defosseux's avatar
CI:  
Raphael Defosseux committed
373 374 375
                                def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): Some modified files in Merge Request MAY have INTRODUCED WARNINGS (" + fileList + ")"
                                addGitLabMRComment comment: message
                            }
376
                        } else {
377
                            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}"
378 379
                        }
                        if(fileExists('build_results.html')) {
380
                            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"
381 382 383 384 385 386
                            archiveArtifacts artifacts: 'build_results.html'
                        }
                    }
                }
            }
        }
Raphael Defosseux's avatar
Raphael Defosseux committed
387

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

718 719 720 721 722 723
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!',
724
                     to: gitCommitAuthorEmailAddr
725 726 727 728

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

// ----  Slave Job functions

def triggerSlaveJob (jobName, gitlabStatusName) {
763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782
    // 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"
783 784 785 786 787
        }
    }
}

def triggerSlaveJobNoGitLab (jobName) {
788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803
    // 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"
804
    } else {
805 806
       echo "${jobName} Slave Job is KO"
       sh "ci-scripts/fail.sh"
807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822
    }
}

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