Jenkinsfile-gitlab 24.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
Raphael Defosseux committed
33
def doRedHatBuild = false
34
def FDD_Band7_B210_Status
35
def TDD_Band40_B210_Status
Raphael Defosseux's avatar
Raphael Defosseux committed
36

37 38 39 40 41 42 43 44
pipeline {
    agent {
        label 'bellatrix'
    }
    options {
        disableConcurrentBuilds()
        timestamps()
        gitLabConnection('OAI GitLab')
45
        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"])
Raphael Defosseux's avatar
Raphael Defosseux committed
46
        ansiColor('xterm')
47 48 49
    }

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

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

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

117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
        stage ("Start VM -- cppcheck") {
            steps {
                sh "./ci-scripts/createVM.sh --variant cppcheck --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
            }
        }

        stage ("Start VM -- enb-usrp") {
            steps {
                sh "./ci-scripts/createVM.sh --variant enb-usrp --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
            }
        }

        stage ("Start VM -- basic-sim") {
            steps {
                sh "./ci-scripts/createVM.sh --variant basic-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
            }
        }

        stage ("Start VM -- phy-sim") {
            steps {
                sh "./ci-scripts/createVM.sh --variant phy-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
            }
        }

        stage ("Start VM -- enb-ethernet") {
            steps {
                sh "./ci-scripts/createVM.sh --variant enb-ethernet --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
            }
        }

        stage ("Start VM -- ue-ethernet") {
            steps {
                sh "./ci-scripts/createVM.sh --variant ue-ethernet --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
            }
        }

153 154
        stage ("Variant Builds") {
            parallel {
155 156 157
                stage ("Analysis with cppcheck") {
                    steps {
                        gitlabCommitStatus(name: "Analysis with cppcheck") {
158
                            sh "./ci-scripts/buildOnVM.sh --workspace $WORKSPACE --variant cppcheck --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
159 160 161
                        }
                    }
                }
162 163 164
                stage ("Build eNb-USRP") {
                    steps {
                        gitlabCommitStatus(name: "Build eNb-USRP") {
165
                            sh "./ci-scripts/buildOnVM.sh --workspace $WORKSPACE --variant enb-usrp --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
166 167 168 169 170 171
                        }
                    }
                }
                stage ("Build basic simulator") {
                    steps {
                        gitlabCommitStatus(name: "Build basic-sim") {
172
                            sh "./ci-scripts/buildOnVM.sh --workspace $WORKSPACE --variant basic-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep-vm-alive"
173 174
                        }
                    }
175
                }
Raphael Defosseux's avatar
Raphael Defosseux committed
176 177 178
                stage ("Build physical simulators") {
                    steps {
                        gitlabCommitStatus(name: "Build phy-sim") {
179
                            sh "./ci-scripts/buildOnVM.sh --workspace $WORKSPACE --variant phy-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep-vm-alive"
Raphael Defosseux's avatar
Raphael Defosseux committed
180 181 182
                        }
                    }
                }
183 184 185 186 187 188 189 190 191 192 193 194 195 196
                stage ("Build eNb-ethernet") {
                    steps {
                        gitlabCommitStatus(name: "Build eNb-ethernet") {
                            sh "./ci-scripts/buildOnVM.sh --workspace $WORKSPACE --variant enb-ethernet --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep-vm-alive"
                        }
                    }
                }
                stage ("Build UE-ethernet") {
                    steps {
                        gitlabCommitStatus(name: "Build UE-ethernet") {
                            sh "./ci-scripts/buildOnVM.sh --workspace $WORKSPACE --variant ue-ethernet --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep-vm-alive"
                        }
                    }
                }
Raphael Defosseux's avatar
Raphael Defosseux committed
197 198 199 200 201
                stage ("Build eNb-USRP on Red Hat") {
                    when {
                        expression {doRedHatBuild}
                    }
                    steps {
Raphael Defosseux's avatar
Raphael Defosseux committed
202 203 204 205 206 207 208 209 210 211
                        gitlabCommitStatus(name: "Build eNb-USRP-CentOS") {
                            script {
                                try {
                                    withCredentials([
                                        [$class: 'UsernamePasswordMultiBinding', credentialsId: "${params.RedHatRemoteCredentials}", usernameVariable: 'RH_Username', passwordVariable: 'RH_Password']
                                    ]) {
                                        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}"
                                    }
                                } catch (Exception e) {
                                    echo "Red Hat build failed not an error now"
Raphael Defosseux's avatar
Raphael Defosseux committed
212 213 214 215 216
                                }
                            }
                        }
                    }
                }
217 218 219 220
            }
            post {
                always {
                    script {
221
                        dir ('archives') {
Raphael Defosseux's avatar
Raphael Defosseux committed
222
                            sh "zip -r -qq vm_build_logs.zip basic_sim enb_usrp phy_sim cppcheck enb_eth ue_eth red_hat"
223 224 225
                        }
                        if(fileExists('archives/vm_build_logs.zip')) {
                            archiveArtifacts artifacts: 'archives/vm_build_logs.zip'
226 227 228
                        }
                        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
Raphael Defosseux committed
229 230 231 232 233
                            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 {
234
                                def fileList=readFile('./oai_warning_files_list.txt').trim();
Raphael Defosseux's avatar
Raphael Defosseux committed
235 236 237
                                def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): Some modified files in Merge Request MAY have INTRODUCED WARNINGS (" + fileList + ")"
                                addGitLabMRComment comment: message
                            }
238 239 240 241
                        } 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')) {
Raphael Defosseux's avatar
Raphael Defosseux committed
242
                            sh "sed -i -e 's#Build-ID: ${BUILD_ID}#Build-ID: <a href=\"{BUILD_URL}\">${BUILD_ID}</a>#' build_results.html"
243 244 245 246 247 248
                            archiveArtifacts artifacts: 'build_results.html'
                        }
                    }
                }
            }
        }
Raphael Defosseux's avatar
Raphael Defosseux committed
249

250 251 252 253 254
        stage ("Variant Tests") {
            parallel {
                stage ("Test physical simulators") {
                    steps {
                        gitlabCommitStatus(name: "Test phy-sim") {
255
                            sh "./ci-scripts/runTestOnVM.sh --workspace $WORKSPACE --variant phy-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
256 257 258 259 260
                        }
                    }
                }
                stage ("Test basic simulator") {
                    steps {
261
                        gitlabCommitStatus(name: "Test basic-sim") {
Raphael Defosseux's avatar
Raphael Defosseux committed
262
                            sh "./ci-scripts/runTestOnVM.sh --workspace $WORKSPACE --variant basic-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep-vm-alive"
263
                        }
264 265
                    }
                }
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289
                stage ("Test on CI bench #1") {
                    stages {
                        stage ("Test FDD - Band 7 - B210") {
                            steps {
                                gitlabCommitStatus(name: "Test-FDD-Band7") {
                                    script {
                                        if ("MERGE".equals(env.gitlabActionType)) {
                                            FDD_Band7_B210_Status = 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 {
                                            FDD_Band7_B210_Status = 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
290
                                }
291
                            }
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317
                            post {
                                // In case of success we really pick the report from the exact slave build number
                                success {
                                    script {
                                        copyArtifacts(projectName: 'eNB-CI-FDD-Band7-B210',
                                                      filter: 'test_results*.html',
                                                      selector: specific("${FDD_Band7_B210_Status.number}"))
                                        if (fileExists('test_results-eNB-CI-FDD-Band7-B210.html')) {
                                            archiveArtifacts artifacts: 'test_results-eNB-CI-FDD-Band7-B210.html'
                                        }
                                    }
                                }
                                // In case of any non-success, we are retrieving the HTML report of the last completed
                                // slave job. Note that we could use that syntax also in case of success.
                                // The only drop-back is that we may retrieve the HTML report of a previous build
                                cleanup {
                                    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')) {
                                                archiveArtifacts artifacts: 'test_results-eNB-CI-FDD-Band7-B210.html'
                                            }
                                        }
                                    }
318 319 320
                                }
                            }
                        }
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369
                        stage ("Test TDD - Band 40 - B210") {
                            steps {
                                gitlabCommitStatus(name: "Test-TDD-Band40") {
                                    script {
                                        if ("MERGE".equals(env.gitlabActionType)) {
                                            TDD_Band40_B210_Status = 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 {
                                            TDD_Band40_B210_Status = 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)
                                               ]
                                        }
                                    }
                                }
                            }
                            post {
                                // In case of success we really pick the report from the exact slave build number
                                success {
                                    script {
                                        copyArtifacts(projectName: 'eNB-CI-TDD-Band40-B210',
                                                      filter: 'test_results*.html',
                                                      selector: specific("${TDD_Band40_B210_Status.number}"))
                                        if (fileExists('test_results-eNB-CI-TDD-Band40-B210.html')) {
                                            archiveArtifacts artifacts: 'test_results-eNB-CI-TDD-Band40-B210.html'
                                        }
                                    }
                                }
                                // In case of any non-success, we are retrieving the HTML report of the last completed
                                // slave job. Note that we could use that syntax also in case of success.
                                // The only drop-back is that we may retrieve the HTML report of a previous build
                                cleanup {
                                    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')) {
                                                archiveArtifacts artifacts: 'test_results-eNB-CI-TDD-Band40-B210.html'
                                            }
                                        }
Raphael Defosseux's avatar
Raphael Defosseux committed
370 371 372 373
                                    }
                                }
                            }
                        }
374
                    }
375
                }
376 377 378 379 380
            }
            post {
                always {
                    script {
                        dir ('archives') {
381
                            sh "if [ -d basic_sim/test ] || [ -d phy_sim/test ]; then zip -r -qq vm_tests_logs.zip */test ; fi"
382 383 384
                        }
                        if(fileExists('archives/vm_tests_logs.zip')) {
                            archiveArtifacts artifacts: 'archives/vm_tests_logs.zip'
385 386 387 388 389 390
                            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')) {
Raphael Defosseux's avatar
Raphael Defosseux committed
391
                                sh "sed -i -e 's#Build-ID: ${BUILD_ID}#Build-ID: <a href=\"{BUILD_URL}\">${BUILD_ID}</a>#' test_simulator_results.html"
392 393
                                archiveArtifacts artifacts: 'test_simulator_results.html'
                            }
394 395 396 397 398
                        }
                    }
                }
            }
        }
Raphael Defosseux's avatar
Raphael Defosseux committed
399 400 401 402 403
        stage ("Destroy all Virtual Machines") {
            steps {
                sh "./ci-scripts/destroyAllRunningVM.sh --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
            }
        }
404 405 406
    }
    post {
        always {
407
            script {
Raphael Defosseux's avatar
Raphael Defosseux committed
408 409
                // Stage destroy may not be run if error in previous stage
                sh "./ci-scripts/destroyAllRunningVM.sh --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
410
            }
411 412 413
        }
        success {
            script {
414
                def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): passed (" + BUILD_URL + ")"
415 416 417
                if ("MERGE".equals(env.gitlabActionType)) {
                    echo "This is a MERGE event"
                    addGitLabMRComment comment: message
418
                    def message2 = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): passed (" + BUILD_URL + ") -- MergeRequest #" + env.gitlabMergeRequestIid + " (" + env.gitlabMergeRequestTitle + ")"
419
                    sendSocialMediaMessage('ci-enb', 'good', message2)
420
                } else {
421
                    sendSocialMediaMessage('ci-enb', 'good', message)
422 423 424 425 426
                }
            }
        }
        failure {
            script {
427
                def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): failed (" + BUILD_URL + ")"
428 429 430
                if ("MERGE".equals(env.gitlabActionType)) {
                    echo "This is a MERGE event"
                    addGitLabMRComment comment: message
431
                    def message2 = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): failed (" + BUILD_URL + ") -- MergeRequest #" + env.gitlabMergeRequestIid + " (" + env.gitlabMergeRequestTitle + ")"
432
                    sendSocialMediaMessage('ci-enb', 'danger', message2)
433
                } else {
434
                    sendSocialMediaMessage('ci-enb', 'danger', message)
435 436 437 438 439
                }
            }
        }
    }
}