Jenkinsfile-gitlab 9.21 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
// Comments

pipeline {
    agent {
        label 'bellatrix'
    }
    options {
        disableConcurrentBuilds()
        timestamps()
        gitLabConnection('OAI GitLab')
Raphael Defosseux's avatar
Raphael Defosseux committed
11
        gitlabBuilds(builds: ["Build eNb-USRP", "Build basic-sim", "Build phy-sim", "Build eNb-ethernet", "Build UE-ethernet", "Analysis with cppcheck"])
12 13 14
    }

    stages {
15
        stage ("Verify Guidelines") {
16 17 18 19 20
            steps {
                echo "Git URL         is ${GIT_URL}"
                echo "GitLab Act      is ${env.gitlabActionType}"
                script {
                    if ("MERGE".equals(env.gitlabActionType)) {
21
                        // GitLab-Jenkins plugin integration is lacking to perform the merge by itself
22
                        // Doing it manually --> it may have merge conflicts
23
                        sh "./ci-scripts/doGitLabMerge.sh --src-branch ${env.gitlabSourceBranch} --src-commit ${env.gitlabMergeRequestLastCommit} --target-branch ${env.gitlabTargetBranch} --target-commit ${GIT_COMMIT}"
24
                        sh "zip -r -qq localZip.zip ."
25 26 27 28

                        // 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}"
29 30
                        def res=readFile('./oai_rules_result.txt').trim();
                        if ("0".equals(res)) {
31 32
                            def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): All Changed files in Merge Request follow OAI Formatting Rules"
                            addGitLabMRComment comment: message
33
                        } else {
34 35
                            def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): Some Changed files in Merge Request DO NOT follow OAI Formatting Rules"
                            addGitLabMRComment comment: message
36 37 38 39
                        }
                    } else {
                        echo "Git Branch      is ${GIT_BRANCH}"
                        echo "Git Commit      is ${GIT_COMMIT}"
40

41
                        sh "zip -r -qq localZip.zip ."
42 43
                        // 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
44
                        sh "./ci-scripts/checkCodingFormattingRules.sh"
45 46 47 48
                    }
                }
            }
        }
49

50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
        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}"
            }
        }

86 87
        stage ("Variant Builds") {
            parallel {
88 89 90
                stage ("Analysis with cppcheck") {
                    steps {
                        gitlabCommitStatus(name: "Analysis with cppcheck") {
91
                            sh "./ci-scripts/buildOnVM.sh --workspace $WORKSPACE --variant cppcheck --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep-vm-alive"
92 93 94
                        }
                    }
                }
95 96 97
                stage ("Build eNb-USRP") {
                    steps {
                        gitlabCommitStatus(name: "Build eNb-USRP") {
98
                            sh "./ci-scripts/buildOnVM.sh --workspace $WORKSPACE --variant enb-usrp --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep-vm-alive"
99 100 101 102 103 104
                        }
                    }
                }
                stage ("Build basic simulator") {
                    steps {
                        gitlabCommitStatus(name: "Build basic-sim") {
105
                            sh "./ci-scripts/buildOnVM.sh --workspace $WORKSPACE --variant basic-sim --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep-vm-alive"
106 107
                        }
                    }
108
                }
Raphael Defosseux's avatar
Raphael Defosseux committed
109 110 111
                stage ("Build physical simulators") {
                    steps {
                        gitlabCommitStatus(name: "Build phy-sim") {
112
                            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
113 114 115
                        }
                    }
                }
116 117 118 119 120 121 122 123 124 125 126 127 128 129
                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"
                        }
                    }
                }
130 131 132 133
            }
            post {
                always {
                    script {
134
                        dir ('archives') {
135
                            sh "zip -r -qq vm_build_logs.zip basic_sim enb_usrp phy_sim cppcheck enb_eth ue_eth"
136 137 138
                        }
                        if(fileExists('archives/vm_build_logs.zip')) {
                            archiveArtifacts artifacts: 'archives/vm_build_logs.zip'
139 140 141 142 143 144 145 146 147 148 149 150 151
                        }
                        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}"
                        } 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')) {
                            archiveArtifacts artifacts: 'build_results.html'
                        }
                    }
                }
            }
        }
Raphael Defosseux's avatar
Raphael Defosseux committed
152 153 154 155 156 157

        stage ("Destroy all Virtual Machines") {
            steps {
                sh "./ci-scripts/destroyAllRunningVM.sh --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
            }
        }
158 159 160
    }
    post {
        always {
161
            script {
Raphael Defosseux's avatar
Raphael Defosseux committed
162 163
                // Stage destroy may not be run if error in previous stage
                sh "./ci-scripts/destroyAllRunningVM.sh --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
164
            }
165 166 167
        }
        success {
            script {
168
                def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): passed (" + BUILD_URL + ")"
169 170 171
                if ("MERGE".equals(env.gitlabActionType)) {
                    echo "This is a MERGE event"
                    addGitLabMRComment comment: message
172
                    def message2 = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): passed (" + BUILD_URL + ") -- MergeRequest #" + env.gitlabMergeRequestIid + " (" + env.gitlabMergeRequestTitle + ")"
173 174 175 176 177 178 179 180
                    slackSend channel: 'ci-enb', color: 'good', message: message2
                } else {
                    slackSend channel: 'ci-enb', color: 'good', message: message
                }
            }
        }
        failure {
            script {
181
                def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): failed (" + BUILD_URL + ")"
182 183 184
                if ("MERGE".equals(env.gitlabActionType)) {
                    echo "This is a MERGE event"
                    addGitLabMRComment comment: message
185
                    def message2 = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): failed (" + BUILD_URL + ") -- MergeRequest #" + env.gitlabMergeRequestIid + " (" + env.gitlabMergeRequestTitle + ")"
186 187 188 189 190 191 192 193
                    slackSend channel: 'ci-enb', color: 'danger', message: message2
                } else {
                    slackSend channel: 'ci-enb', color: 'danger', message: message
                }
            }
        }
    }
}