Jenkinsfile-gitlab 33.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

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

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

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

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

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

169 170 171 172 173 174 175 176
        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"
                }
            }
        }

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

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

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

Raphael Defosseux's avatar
Raphael Defosseux committed
313 314 315 316 317
        stage ("Variant Tests") {
            parallel {
                stage ("Test physical simulators") {
                    steps {
                        gitlabCommitStatus(name: "Test phy-sim") {
318
                            timeout (time: 20, unit: 'MINUTES') {
319
                                sh "./ci-scripts/oai-ci-vm-tool test --workspace $WORKSPACE --variant phy-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
320
                            }
Raphael Defosseux's avatar
Raphael Defosseux committed
321 322 323 324 325
                        }
                    }
                }
                stage ("Test basic simulator") {
                    steps {
326
                        gitlabCommitStatus(name: "Test basic-sim") {
327
                            timeout (time: 30, unit: 'MINUTES') {
328
                                sh "./ci-scripts/oai-ci-vm-tool test --workspace $WORKSPACE --variant basic-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
329
                            }
330
                        }
Raphael Defosseux's avatar
Raphael Defosseux committed
331 332
                    }
                }
333 334
                stage ("Test L2 simulator") {
                    steps {
335
                        gitlabCommitStatus(name: "Test L2-sim") {
336 337 338
                            timeout (time: 30, unit: 'MINUTES') {
                                sh "./ci-scripts/oai-ci-vm-tool test --workspace $WORKSPACE --variant l2-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
                            }
339
                        }
340 341
                    }
                }
342 343 344 345 346 347
                stage ("Build Flexran Controller") {
                    when {
                        expression {doFlexranCtrlTest}
                    }
                    steps {
                        timeout (time: 20, unit: 'MINUTES') {
Raphael Defosseux's avatar
Raphael Defosseux committed
348
                            sh "./ci-scripts/oai-ci-vm-tool build --workspace $WORKSPACE --variant flexran-rtc --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep-vm-alive"
349 350 351
                        }
                    }
                }
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373
                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
374
                                }
375
                            }
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390
                        }
                    }
                    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'
391
                                    }
392 393 394
                                }
                            }
                        }
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418
                    }
                }
                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)
                                       ]
419 420
                                }
                            }
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435
                        }
                    }
                    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'
436 437 438 439
                                    }
                                }
                            }
                        }
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463
                    }
                }
                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)
                                       ]
464 465
                                }
                            }
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480
                        }
                    }
                    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'
481 482 483 484
                                    }
                                }
                            }
                        }
485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508
                    }
                }
                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)
                                       ]
509 510
                                }
                            }
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525
                        }
                    }
                    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
526 527 528 529
                                    }
                                }
                            }
                        }
530
                    }
531
                }
Raphael Defosseux's avatar
Raphael Defosseux committed
532 533 534 535 536
            }
            post {
                always {
                    script {
                        dir ('archives') {
537
                            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
538 539 540
                        }
                        if(fileExists('archives/vm_tests_logs.zip')) {
                            archiveArtifacts artifacts: 'archives/vm_tests_logs.zip'
541
                            if ("MERGE".equals(env.gitlabActionType)) {
542
                                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}"
543
                            } else {
544
                                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}"
545 546
                            }
                            if(fileExists('test_simulator_results.html')) {
547
                                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"
548 549
                                archiveArtifacts artifacts: 'test_simulator_results.html'
                            }
Raphael Defosseux's avatar
Raphael Defosseux committed
550 551 552 553 554
                        }
                    }
                }
            }
        }
Raphael Defosseux's avatar
Raphael Defosseux committed
555 556
        stage ("Destroy all Virtual Machines") {
            steps {
557
                sh "./ci-scripts/oai-ci-vm-tool destroy --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
Raphael Defosseux's avatar
Raphael Defosseux committed
558 559
            }
        }
560 561 562
    }
    post {
        always {
563
            script {
Raphael Defosseux's avatar
Raphael Defosseux committed
564
                // Stage destroy may not be run if error in previous stage
565
                sh "./ci-scripts/oai-ci-vm-tool destroy --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
566 567 568 569 570 571 572 573 574
                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
575
            }
576 577 578
        }
        success {
            script {
579
                def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): passed (" + BUILD_URL + ")"
580 581 582
                if ("MERGE".equals(env.gitlabActionType)) {
                    echo "This is a MERGE event"
                    addGitLabMRComment comment: message
583
                    def message2 = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): passed (" + BUILD_URL + ") -- MergeRequest #" + env.gitlabMergeRequestIid + " (" + env.gitlabMergeRequestTitle + ")"
584
                    sendSocialMediaMessage('ci-enb', 'good', message2)
585
                } else {
586
                    sendSocialMediaMessage('ci-enb', 'good', message)
587 588 589 590 591
                }
            }
        }
        failure {
            script {
592
                def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): failed (" + BUILD_URL + ")"
593 594 595
                if ("MERGE".equals(env.gitlabActionType)) {
                    echo "This is a MERGE event"
                    addGitLabMRComment comment: message
596
                    def message2 = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): failed (" + BUILD_URL + ") -- MergeRequest #" + env.gitlabMergeRequestIid + " (" + env.gitlabMergeRequestTitle + ")"
597
                    sendSocialMediaMessage('ci-enb', 'danger', message2)
598
                } else {
599
                    sendSocialMediaMessage('ci-enb', 'danger', message)
600 601 602 603 604
                }
            }
        }
    }
}