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

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

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

35 36 37 38 39 40 41 42
pipeline {
    agent {
        label 'bellatrix'
    }
    options {
        disableConcurrentBuilds()
        timestamps()
        gitLabConnection('OAI GitLab')
43
        gitlabBuilds(builds: ["Build eNb-USRP", "Build basic-sim", "Build gNb-usrp", "Build nr-UE-usrp", "Build phy-sim", "Build eNb-ethernet", "Build UE-ethernet", "Analysis with cppcheck", "Test phy-sim", "Test basic-sim", "Test-FDD-Band7", "Test-TDD-Band40", "Test-IF4p5-FDD-Band7", "Test-IF4p5-TDD-Band40"])
Raphael Defosseux's avatar
CI:  
Raphael Defosseux committed
44
        ansiColor('xterm')
45 46 47
    }

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

                        // 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}"
89 90
                        def res=readFile('./oai_rules_result.txt').trim();
                        if ("0".equals(res)) {
91 92
                            def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): All Changed files in Merge Request follow OAI Formatting Rules"
                            addGitLabMRComment comment: message
93
                        } else {
94 95
                            def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): Some Changed files in Merge Request DO NOT follow OAI Formatting Rules"
                            addGitLabMRComment comment: message
96 97 98 99
                        }
                    } else {
                        echo "Git Branch      is ${GIT_BRANCH}"
                        echo "Git Commit      is ${GIT_COMMIT}"
100

101
                        sh "zip -r -qq localZip.zip ."
102 103
                        // 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
104
                        sh "./ci-scripts/checkCodingFormattingRules.sh"
105 106 107
                    }
                }
            }
108 109
            post {
                failure {
110 111 112 113
                    script {
                        def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): Merge Conflicts -- Cannot perform CI"
                        addGitLabMRComment comment: message
                    }
114 115
                }
            }
116
        }
117

118
        stage ("Start VM -- basic-sim") {
119
            steps {
120
                timeout (time: 5, unit: 'MINUTES') {
121
                    sh "./ci-scripts/buildOnVM.sh --workspace $WORKSPACE --variant basic-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID} --daemon"
122
                }
123 124 125
            }
        }

126
        stage ("Start VM -- gnb-usrp") {
127
            steps {
128
                timeout (time: 5, unit: 'MINUTES') {
129
                    sh "./ci-scripts/buildOnVM.sh --workspace $WORKSPACE --variant gnb-usrp --job-name ${JOB_NAME} --build-id ${BUILD_ID} --daemon"
130
                }
131 132 133
            }
        }

134
        stage ("Start VM -- nu-ue-usrp") {
135
            steps {
136
                timeout (time: 5, unit: 'MINUTES') {
137
                    sh "./ci-scripts/buildOnVM.sh --workspace $WORKSPACE --variant nu-ue-usrp --job-name ${JOB_NAME} --build-id ${BUILD_ID} --daemon"
138
                }
139 140 141
            }
        }

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

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

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

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

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

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

Raphael Defosseux's avatar
Raphael Defosseux committed
311 312 313 314 315
        stage ("Variant Tests") {
            parallel {
                stage ("Test physical simulators") {
                    steps {
                        gitlabCommitStatus(name: "Test phy-sim") {
316 317 318
                            timeout (time: 20, unit: 'MINUTES') {
                                sh "./ci-scripts/runTestOnVM.sh --workspace $WORKSPACE --variant phy-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
                            }
Raphael Defosseux's avatar
Raphael Defosseux committed
319 320 321 322 323
                        }
                    }
                }
                stage ("Test basic simulator") {
                    steps {
324
                        gitlabCommitStatus(name: "Test basic-sim") {
325 326 327
                            timeout (time: 20, unit: 'MINUTES') {
                                sh "./ci-scripts/runTestOnVM.sh --workspace $WORKSPACE --variant basic-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep-vm-alive"
                            }
328
                        }
Raphael Defosseux's avatar
Raphael Defosseux committed
329 330
                    }
                }
331 332 333 334
                stage ("Test on CI bench #1") {
                    stages {
                        stage ("Test FDD - Band 7 - B210") {
                            steps {
335 336 337 338 339
                                script {
                                    try {
                                        if ("MERGE".equals(env.gitlabActionType)) {
                                            gitlabCommitStatus(name: "Test-FDD-Band7") {
                                                build job: 'eNB-CI-FDD-Band7-B210',
340 341 342 343 344 345
                                                   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)
                                                   ]
346 347 348 349
                                            }
                                        } else {
                                            gitlabCommitStatus(name: "Test-FDD-Band7") {
                                                build job: 'eNB-CI-FDD-Band7-B210',
350 351 352 353 354 355 356
                                                   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)
                                                   ]
                                            }
357
                                        }
358 359
                                    } catch (Exception e) {
                                        currentBuild.result = 'FAILURE'
360
                                    }
Raphael Defosseux's avatar
Raphael Defosseux committed
361
                                }
362
                            }
363 364
                            post {
                                // In case of any non-success, we are retrieving the HTML report of the last completed
365
                                // slave job.
366
                                // The only drop-back is that we may retrieve the HTML report of a previous build
367
                                always {
368 369 370 371 372 373
                                    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')) {
374
                                                sh "sed -i -e 's#TEMPLATE_BUILD_TIME#${JOB_TIMESTAMP}#' test_results-eNB-CI-FDD-Band7-B210.html"
375 376 377 378
                                                archiveArtifacts artifacts: 'test_results-eNB-CI-FDD-Band7-B210.html'
                                            }
                                        }
                                    }
379 380 381
                                }
                            }
                        }
382 383
                        stage ("Test TDD - Band 40 - B210") {
                            steps {
384 385 386 387 388
                                script {
                                    try {
                                        if ("MERGE".equals(env.gitlabActionType)) {
                                            gitlabCommitStatus(name: "Test-TDD-Band40") {
                                                build job: 'eNB-CI-TDD-Band40-B210',
389 390 391 392 393 394
                                                   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)
                                                   ]
395 396 397 398
                                            }
                                        } else {
                                            gitlabCommitStatus(name: "Test-TDD-Band40") {
                                                build job: 'eNB-CI-TDD-Band40-B210',
399 400 401 402 403 404 405
                                                   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)
                                                   ]
                                            }
406
                                        }
407 408
                                    } catch (Exception e) {
                                        currentBuild.result = 'FAILURE'
409 410 411 412 413
                                    }
                                }
                            }
                            post {
                                // In case of any non-success, we are retrieving the HTML report of the last completed
414
                                // slave job.
415
                                // The only drop-back is that we may retrieve the HTML report of a previous build
416
                                always {
417 418 419 420 421 422
                                    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')) {
423
                                                sh "sed -i -e 's#TEMPLATE_BUILD_TIME#${JOB_TIMESTAMP}#' test_results-eNB-CI-TDD-Band40-B210.html"
424 425 426
                                                archiveArtifacts artifacts: 'test_results-eNB-CI-TDD-Band40-B210.html'
                                            }
                                        }
427 428 429 430 431 432 433 434 435 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 464 465 466 467 468 469 470 471 472 473 474 475
                                    }
                                }
                            }
                        }
                        stage ("Test IF4p5 - FDD - Band 7 - B210") {
                            steps {
                                script {
                                    try {
                                        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)
                                                   ]
                                            }
                                        }
                                    } catch (Exception e) {
                                        currentBuild.result = 'FAILURE'
                                    }
                                }
                            }
                            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'
                                            }
                                        }
476 477 478 479 480 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 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524
                                    }
                                }
                            }
                        }
                        stage ("Test IF4p5 - TDD - Band 40 - B210") {
                            steps {
                                script {
                                    try {
                                        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)
                                                   ]
                                            }
                                        }
                                    } catch (Exception e) {
                                        currentBuild.result = 'FAILURE'
                                    }
                                }
                            }
                            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
525
                                    }
526 527 528
                                }
                            }
                        }
529
                    }
530
                }
Raphael Defosseux's avatar
Raphael Defosseux committed
531 532 533 534 535
            }
            post {
                always {
                    script {
                        dir ('archives') {
536
                            sh "if [ -d basic_sim/test ] || [ -d phy_sim/test ]; then zip -r -qq vm_tests_logs.zip */test ; fi"
Raphael Defosseux's avatar
Raphael Defosseux committed
537 538 539
                        }
                        if(fileExists('archives/vm_tests_logs.zip')) {
                            archiveArtifacts artifacts: 'archives/vm_tests_logs.zip'
540 541 542 543 544 545
                            if ("MERGE".equals(env.gitlabActionType)) {
                                sh "./ci-scripts/reportTestLocally.sh --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}"
                            } else {
                                sh "./ci-scripts/reportTestLocally.sh --git-url ${GIT_URL} --job-name ${JOB_NAME} --build-id ${BUILD_ID} --trigger push --branch ${GIT_BRANCH} --commit ${GIT_COMMIT}"
                            }
                            if(fileExists('test_simulator_results.html')) {
546
                                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"
547 548
                                archiveArtifacts artifacts: 'test_simulator_results.html'
                            }
Raphael Defosseux's avatar
Raphael Defosseux committed
549 550 551 552 553
                        }
                    }
                }
            }
        }
Raphael Defosseux's avatar
Raphael Defosseux committed
554 555 556 557 558
        stage ("Destroy all Virtual Machines") {
            steps {
                sh "./ci-scripts/destroyAllRunningVM.sh --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
            }
        }
559 560 561
    }
    post {
        always {
562
            script {
Raphael Defosseux's avatar
Raphael Defosseux committed
563 564
                // Stage destroy may not be run if error in previous stage
                sh "./ci-scripts/destroyAllRunningVM.sh --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
565 566 567 568 569 570 571 572 573
                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
574
            }
575 576 577
        }
        success {
            script {
578
                def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): passed (" + BUILD_URL + ")"
579 580 581
                if ("MERGE".equals(env.gitlabActionType)) {
                    echo "This is a MERGE event"
                    addGitLabMRComment comment: message
582
                    def message2 = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): passed (" + BUILD_URL + ") -- MergeRequest #" + env.gitlabMergeRequestIid + " (" + env.gitlabMergeRequestTitle + ")"
583
                    sendSocialMediaMessage('ci-enb', 'good', message2)
584
                } else {
585
                    sendSocialMediaMessage('ci-enb', 'good', message)
586 587 588 589 590
                }
            }
        }
        failure {
            script {
591
                def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): failed (" + BUILD_URL + ")"
592 593 594
                if ("MERGE".equals(env.gitlabActionType)) {
                    echo "This is a MERGE event"
                    addGitLabMRComment comment: message
595
                    def message2 = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): failed (" + BUILD_URL + ") -- MergeRequest #" + env.gitlabMergeRequestIid + " (" + env.gitlabMergeRequestTitle + ")"
596
                    sendSocialMediaMessage('ci-enb', 'danger', message2)
597
                } else {
598
                    sendSocialMediaMessage('ci-enb', 'danger', message)
599 600 601 602 603
                }
            }
        }
    }
}