Jenkinsfile-gitlab 31.9 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-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
        stage ("Start VM -- phy-sim") {
170
            steps {
171
                timeout (time: 5, unit: 'MINUTES') {
172
                    sh "./ci-scripts/oai-ci-vm-tool build --workspace $WORKSPACE --variant phy-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID} --daemon"
173
                }
174 175 176
            }
        }

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

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

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