Jenkinsfile-gitlab 36.8 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
        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", "Test L2-sim", "Test-Mono-FDD-Band7", "Test-Mono-TDD-Band40", "Test-IF4p5-FDD-Band7", "Test-IF4p5-TDD-Band40", "Test-Mono-FDD-Band13", "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)) {
91
                        // since a bit, in push events, gitlabUserEmail is not populated
92
                        gitCommitAuthorEmailAddr = env.gitlabUserEmail
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}"
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 131 132 133 134 135
                    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"
                            }
                            sh "sed -i -e 's#add-apt-repository.*cleishm.*neo4j#add-apt-repository ppa:cleishm/neo4j -y#' -e 's#libneo4j-client-dev#libneo4j-client-dev -y#' tools/install_dependencies"
                            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
        stage ("Start VM -- gnb-usrp") {
158
            steps {
159
                timeout (time: 5, unit: 'MINUTES') {
160
                    sh "./ci-scripts/oai-ci-vm-tool build --workspace $WORKSPACE --variant gnb-usrp --job-name ${JOB_NAME} --build-id ${BUILD_ID} --daemon"
161
                }
162 163 164
            }
        }

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

173
        stage ("Start VM -- enb-usrp") {
174
            steps {
175
                timeout (time: 5, unit: 'MINUTES') {
176
                    sh "./ci-scripts/oai-ci-vm-tool build --workspace $WORKSPACE --variant enb-usrp --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 -- enb-ethernet") {
190
            steps {
191
                timeout (time: 5, unit: 'MINUTES') {
192
                    sh "./ci-scripts/oai-ci-vm-tool build --workspace $WORKSPACE --variant enb-ethernet --job-name ${JOB_NAME} --build-id ${BUILD_ID} --daemon"
193
                }
194 195 196
            }
        }

197
        stage ("Start VM -- ue-ethernet") {
198
            steps {
199
                timeout (time: 5, unit: 'MINUTES') {
200
                    sh "./ci-scripts/oai-ci-vm-tool build --workspace $WORKSPACE --variant ue-ethernet --job-name ${JOB_NAME} --build-id ${BUILD_ID} --daemon"
201
                }
202 203
            }
        }
204
        
205
        stage ("Start VM -- cppcheck") {
206
            steps {
207
                timeout (time: 5, unit: 'MINUTES') {
208
                    sh "./ci-scripts/oai-ci-vm-tool build --workspace $WORKSPACE --variant cppcheck --job-name ${JOB_NAME} --build-id ${BUILD_ID} --daemon"
209
                }
210 211 212
            }
        }

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

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

650 651 652 653 654 655
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!',
656
                     to: gitCommitAuthorEmailAddr
657 658 659 660

                if (fileExists('.git/CI_COMMIT_MSG')) {
                    sh "rm -f .git/CI_COMMIT_MSG"
                }
661
            }
662 663 664
        }
        success {
            script {
665
                def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): passed (" + BUILD_URL + ")"
666 667 668
                if ("MERGE".equals(env.gitlabActionType)) {
                    echo "This is a MERGE event"
                    addGitLabMRComment comment: message
669
                    def message2 = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): passed (" + BUILD_URL + ") -- MergeRequest #" + env.gitlabMergeRequestIid + " (" + env.gitlabMergeRequestTitle + ")"
670
                    sendSocialMediaMessage('ci-enb', 'good', message2)
671
                } else {
672
                    sendSocialMediaMessage('ci-enb', 'good', message)
673 674 675 676 677
                }
            }
        }
        failure {
            script {
678
                def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): failed (" + BUILD_URL + ")"
679 680 681
                if ("MERGE".equals(env.gitlabActionType)) {
                    echo "This is a MERGE event"
                    addGitLabMRComment comment: message
682
                    def message2 = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): failed (" + BUILD_URL + ") -- MergeRequest #" + env.gitlabMergeRequestIid + " (" + env.gitlabMergeRequestTitle + ")"
683
                    sendSocialMediaMessage('ci-enb', 'danger', message2)
684
                } else {
685
                    sendSocialMediaMessage('ci-enb', 'danger', message)
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 739 740 741 742 743 744 745 746 747 748 749 750 751 752

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