Jenkinsfile-gitlab 35.1 KB
Newer Older
1
#!/bin/groovy
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
 * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The OpenAirInterface Software Alliance licenses this file to You under
 * the OAI Public License, Version 1.1  (the "License"); you may not use this file
 * except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.openairinterface.org/?page_id=698
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *-------------------------------------------------------------------------------
 * For more information about the OpenAirInterface (OAI) Software Alliance:
 *      contact@openairinterface.org
 */
22

23 24 25 26 27 28 29 30 31 32
// Abstraction function to send social media messages:
// like on Slack or Mattermost
def sendSocialMediaMessage(pipeChannel, pipeColor, pipeMessage) {
    if (params.pipelineUsesSlack != null) {
        if (params.pipelineUsesSlack) {
            slackSend channel: pipeChannel, color: pipeColor, message: pipeMessage
        }
    }
}

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 39 40 41 42 43
pipeline {
    agent {
        label 'bellatrix'
    }
    options {
        disableConcurrentBuilds()
        timestamps()
        gitLabConnection('OAI GitLab')
44
        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-FDD-Band7", "Test-TDD-Band40", "Test-IF4p5-FDD-Band7", "Test-IF4p5-TDD-Band40"])
Raphael Defosseux's avatar
CI:  
Raphael Defosseux committed
45
        ansiColor('xterm')
46 47 48
    }

    stages {
Raphael Defosseux's avatar
CI:  
Raphael Defosseux committed
49 50 51
        stage ("Verify Parameters") {
            steps {
                script {
52 53 54
                    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
55 56 57 58 59 60 61 62 63 64 65 66 67
                    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) {
68
                        echo "Performing Red Hat Build"
Raphael Defosseux's avatar
CI:  
Raphael Defosseux committed
69 70 71 72
                        doRedHatBuild = true
                    } else {
                        doRedHatBuild = false
                    }
73
                    if (params.FlexRanRtcGitLabRepository_Credentials != null) {
Raphael Defosseux's avatar
Raphael Defosseux committed
74
                        doFlexranCtrlTest = true
75 76 77 78
                    }
                    if (fileExists("flexran")) {
                        sh "rm -Rf flexran > /dev/null 2>&1"
                    }
Raphael Defosseux's avatar
CI:  
Raphael Defosseux committed
79 80 81
                }
            }
        }
82
        stage ("Verify Guidelines") {
83 84 85 86 87
            steps {
                echo "Git URL         is ${GIT_URL}"
                echo "GitLab Act      is ${env.gitlabActionType}"
                script {
                    if ("MERGE".equals(env.gitlabActionType)) {
88
                        // GitLab-Jenkins plugin integration is lacking to perform the merge by itself
89
                        // Doing it manually --> it may have merge conflicts
90
                        sh "./ci-scripts/doGitLabMerge.sh --src-branch ${env.gitlabSourceBranch} --src-commit ${env.gitlabMergeRequestLastCommit} --target-branch ${env.gitlabTargetBranch} --target-commit ${GIT_COMMIT}"
91
                        sh "zip -r -qq localZip.zip ."
92 93 94 95

                        // 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}"
96 97
                        def res=readFile('./oai_rules_result.txt').trim();
                        if ("0".equals(res)) {
98 99
                            def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): All Changed files in Merge Request follow OAI Formatting Rules"
                            addGitLabMRComment comment: message
100
                        } else {
101 102
                            def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): Some Changed files in Merge Request DO NOT follow OAI Formatting Rules"
                            addGitLabMRComment comment: message
103 104 105 106
                        }
                    } else {
                        echo "Git Branch      is ${GIT_BRANCH}"
                        echo "Git Commit      is ${GIT_COMMIT}"
107
                        sh "git log -n1 --pretty=format:\"%s\" > .git/CI_COMMIT_MSG"
108

109
                        sh "zip -r -qq localZip.zip ."
110 111
                        // 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
112
                        sh "./ci-scripts/checkCodingFormattingRules.sh"
113
                    }
114 115 116 117 118 119 120 121 122 123 124 125
                    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 ."
                        }
                    }
126 127
                }
            }
128 129
            post {
                failure {
130 131 132 133
                    script {
                        def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): Merge Conflicts -- Cannot perform CI"
                        addGitLabMRComment comment: message
                    }
134 135
                }
            }
136
        }
137

138
        stage ("Start VM -- basic-sim") {
139
            steps {
140
                timeout (time: 5, unit: 'MINUTES') {
141
                    sh "./ci-scripts/oai-ci-vm-tool build --workspace $WORKSPACE --variant basic-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID} --daemon"
142
                }
143 144 145 146 147
            }
        }

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

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

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

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

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

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

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

Raphael Defosseux's avatar
Raphael Defosseux committed
314 315
        stage ("Variant Tests") {
            parallel {
316 317 318 319
                stage ("VM-based tests") {
                    stages {
                        stage ("Test physical simulators") {
                            steps {
320 321 322 323 324 325 326 327 328
                                script {
                                    gitlabCommitStatus(name: "Test phy-sim") {
                                        timeout (time: 20, unit: 'MINUTES') {
                                            try {
                                                sh "./ci-scripts/oai-ci-vm-tool test --workspace $WORKSPACE --variant phy-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
                                            } catch (Exception e) {
                                              currentBuild.result = 'FAILURE'
                                            }
                                        }
329 330
                                    }
                                }
331
                            }
Raphael Defosseux's avatar
Raphael Defosseux committed
332
                        }
333 334 335 336 337
                        stage ("Build Flexran Controller") {
                            when {
                                expression {doFlexranCtrlTest}
                            }
                            steps {
338 339 340 341 342 343 344 345
                                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'
                                        }
                                    }
346
                                }
347
                            }
348
                        }
349 350
                        stage ("Test basic simulator") {
                            steps {
351 352 353 354 355 356 357 358 359
                                script {
                                    gitlabCommitStatus(name: "Test basic-sim") {
                                        timeout (time: 30, unit: 'MINUTES') {
                                            try {
                                                sh "./ci-scripts/oai-ci-vm-tool test --workspace $WORKSPACE --variant basic-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
                                            } catch (Exception e) {
                                              currentBuild.result = 'FAILURE'
                                            }
                                        }
360 361
                                    }
                                }
362
                            }
363
                        }
364 365
                        stage ("Test L2 simulator") {
                            steps {
366 367 368 369 370 371 372 373 374
                                script {
                                    gitlabCommitStatus(name: "Test L2-sim") {
                                        timeout (time: 30, unit: 'MINUTES') {
                                            try {
                                                sh "./ci-scripts/oai-ci-vm-tool test --workspace $WORKSPACE --variant l2-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
                                            } catch (Exception e) {
                                                currentBuild.result = 'FAILURE'
                                            }
                                        }
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
                stage ("Test FDD - Band 7 - B210") {
                    steps {
                        script {
                            if ("MERGE".equals(env.gitlabActionType)) {
                                gitlabCommitStatus(name: "Test-FDD-Band7") {
                                    build job: 'eNB-CI-FDD-Band7-B210',
                                       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)
                                       ]
                                }
                            } else {
                                gitlabCommitStatus(name: "Test-FDD-Band7") {
                                    build job: 'eNB-CI-FDD-Band7-B210',
                                       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)
                                       ]
Raphael Defosseux's avatar
Raphael Defosseux committed
403
                                }
404
                            }
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419
                        }
                    }
                    post {
                        // 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
                        always {
                            script {
                                if (!fileExists('test_results-eNB-CI-FDD-Band7-B210.html')) {
                                    copyArtifacts(projectName: 'eNB-CI-FDD-Band7-B210',
                                                  filter: 'test_results*.html',
                                                  selector: lastCompleted())
                                    if (fileExists('test_results-eNB-CI-FDD-Band7-B210.html')) {
                                        sh "sed -i -e 's#TEMPLATE_BUILD_TIME#${JOB_TIMESTAMP}#' test_results-eNB-CI-FDD-Band7-B210.html"
                                        archiveArtifacts artifacts: 'test_results-eNB-CI-FDD-Band7-B210.html'
420
                                    }
421 422 423
                                }
                            }
                        }
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447
                    }
                }
                stage ("Test TDD - Band 40 - B210") {
                    steps {
                        script {
                            if ("MERGE".equals(env.gitlabActionType)) {
                                gitlabCommitStatus(name: "Test-TDD-Band40") {
                                    build job: 'eNB-CI-TDD-Band40-B210',
                                       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)
                                       ]
                                }
                            } else {
                                gitlabCommitStatus(name: "Test-TDD-Band40") {
                                    build job: 'eNB-CI-TDD-Band40-B210',
                                       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)
                                       ]
448 449
                                }
                            }
450 451 452 453 454 455 456 457 458 459 460 461 462 463 464
                        }
                    }
                    post {
                        // 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
                        always {
                            script {
                                if (!fileExists('test_results-eNB-CI-TDD-Band40-B210.html')) {
                                    copyArtifacts(projectName: 'eNB-CI-TDD-Band40-B210',
                                                  filter: 'test_results*.html',
                                                  selector: lastCompleted())
                                    if (fileExists('test_results-eNB-CI-TDD-Band40-B210.html')) {
                                        sh "sed -i -e 's#TEMPLATE_BUILD_TIME#${JOB_TIMESTAMP}#' test_results-eNB-CI-TDD-Band40-B210.html"
                                        archiveArtifacts artifacts: 'test_results-eNB-CI-TDD-Band40-B210.html'
465 466 467 468
                                    }
                                }
                            }
                        }
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492
                    }
                }
                stage ("Test IF4p5 - FDD - Band 7 - B210") {
                    steps {
                        script {
                            if ("MERGE".equals(env.gitlabActionType)) {
                                gitlabCommitStatus(name: "Test-IF4p5-FDD-Band7") {
                                    build job: 'eNB-CI-IF4p5-FDD-Band7-B210',
                                       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)
                                       ]
                                }
                            } else {
                                gitlabCommitStatus(name: "Test-IF4p5-FDD-Band7") {
                                    build job: 'eNB-CI-IF4p5-FDD-Band7-B210',
                                       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)
                                       ]
493 494
                                }
                            }
495 496 497 498 499 500 501 502 503 504 505 506 507 508 509
                        }
                    }
                    post {
                        // 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
                        always {
                            script {
                                if (!fileExists('test_results-eNB-CI-IF4p5-FDD-Band7-B210.html')) {
                                    copyArtifacts(projectName: 'eNB-CI-IF4p5-FDD-Band7-B210',
                                                  filter: 'test_results*.html',
                                                  selector: lastCompleted())
                                    if (fileExists('test_results-eNB-CI-IF4p5-FDD-Band7-B210.html')) {
                                        sh "sed -i -e 's#TEMPLATE_BUILD_TIME#${JOB_TIMESTAMP}#' test_results-eNB-CI-IF4p5-FDD-Band7-B210.html"
                                        archiveArtifacts artifacts: 'test_results-eNB-CI-IF4p5-FDD-Band7-B210.html'
510 511 512 513
                                    }
                                }
                            }
                        }
514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537
                    }
                }
                stage ("Test IF4p5 - TDD - Band 40 - B210") {
                    steps {
                        script {
                            if ("MERGE".equals(env.gitlabActionType)) {
                                gitlabCommitStatus(name: "Test-IF4p5-TDD-Band40") {
                                    build job: 'eNB-CI-IF4p5-TDD-Band40-B210',
                                       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)
                                       ]
                                }
                            } else {
                                gitlabCommitStatus(name: "Test-IF4p5-TDD-Band40") {
                                    build job: 'eNB-CI-IF4p5-TDD-Band40-B210',
                                       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)
                                       ]
538 539
                                }
                            }
540 541 542 543 544 545 546 547 548 549 550 551 552 553 554
                        }
                    }
                    post {
                        // 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
                        always {
                            script {
                                if (!fileExists('test_results-eNB-CI-IF4p5-TDD-Band40-B210.html')) {
                                    copyArtifacts(projectName: 'eNB-CI-IF4p5-TDD-Band40-B210',
                                                  filter: 'test_results*.html',
                                                  selector: lastCompleted())
                                    if (fileExists('test_results-eNB-CI-IF4p5-TDD-Band40-B210.html')) {
                                        sh "sed -i -e 's#TEMPLATE_BUILD_TIME#${JOB_TIMESTAMP}#' test_results-eNB-CI-IF4p5-TDD-Band40-B210.html"
                                        archiveArtifacts artifacts: 'test_results-eNB-CI-IF4p5-TDD-Band40-B210.html'
Raphael Defosseux's avatar
CI:  
Raphael Defosseux committed
555 556 557 558
                                    }
                                }
                            }
                        }
559
                    }
560
                }
Raphael Defosseux's avatar
Raphael Defosseux committed
561 562 563 564 565
            }
            post {
                always {
                    script {
                        dir ('archives') {
566
                            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
567 568 569
                        }
                        if(fileExists('archives/vm_tests_logs.zip')) {
                            archiveArtifacts artifacts: 'archives/vm_tests_logs.zip'
570
                            if ("MERGE".equals(env.gitlabActionType)) {
571
                                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}"
572
                            } else {
573
                                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}"
574 575
                            }
                            if(fileExists('test_simulator_results.html')) {
576
                                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"
577 578
                                archiveArtifacts artifacts: 'test_simulator_results.html'
                            }
Raphael Defosseux's avatar
Raphael Defosseux committed
579 580 581 582 583
                        }
                    }
                }
            }
        }
Raphael Defosseux's avatar
Raphael Defosseux committed
584 585
        stage ("Destroy all Virtual Machines") {
            steps {
586
                sh "./ci-scripts/oai-ci-vm-tool destroy --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
Raphael Defosseux's avatar
Raphael Defosseux committed
587 588
            }
        }
589 590 591
    }
    post {
        always {
592
            script {
Raphael Defosseux's avatar
Raphael Defosseux committed
593
                // Stage destroy may not be run if error in previous stage
594
                sh "./ci-scripts/oai-ci-vm-tool destroy --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
595 596 597 598 599 600 601 602 603
                emailext attachmentsPattern: '*results*.html',
                     body: '''Hi,
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!',
                     to: env.gitlabUserEmail
604 605 606 607

                if (fileExists('.git/CI_COMMIT_MSG')) {
                    sh "rm -f .git/CI_COMMIT_MSG"
                }
608
            }
609 610 611
        }
        success {
            script {
612
                def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): passed (" + BUILD_URL + ")"
613 614 615
                if ("MERGE".equals(env.gitlabActionType)) {
                    echo "This is a MERGE event"
                    addGitLabMRComment comment: message
616
                    def message2 = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): passed (" + BUILD_URL + ") -- MergeRequest #" + env.gitlabMergeRequestIid + " (" + env.gitlabMergeRequestTitle + ")"
617
                    sendSocialMediaMessage('ci-enb', 'good', message2)
618
                } else {
619
                    sendSocialMediaMessage('ci-enb', 'good', message)
620 621 622 623 624
                }
            }
        }
        failure {
            script {
625
                def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): failed (" + BUILD_URL + ")"
626 627 628
                if ("MERGE".equals(env.gitlabActionType)) {
                    echo "This is a MERGE event"
                    addGitLabMRComment comment: message
629
                    def message2 = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): failed (" + BUILD_URL + ") -- MergeRequest #" + env.gitlabMergeRequestIid + " (" + env.gitlabMergeRequestTitle + ")"
630
                    sendSocialMediaMessage('ci-enb', 'danger', message2)
631
                } else {
632
                    sendSocialMediaMessage('ci-enb', 'danger', message)
633 634 635 636 637
                }
            }
        }
    }
}