test-boris-Jenkinsfile 8.7 KB
Newer Older
Boris Djalal's avatar
Boris Djalal committed
1
#!/bin/groovy
Boris Djalal's avatar
Boris Djalal committed
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
 */
Boris Djalal's avatar
Boris Djalal committed
22

Boris Djalal's avatar
Save  
Boris Djalal committed
23 24 25 26 27 28 29 30 31 32 33 34 35

// Location of the test XML file to be run
def testXMLFile = params.pythonTestXmlFile
def mainPythonAllXmlFiles = ""
def buildStageStatus = true

// Global Parameters.
def eNB_Repository
def eNB_Branch
def eNB_CommitID
def eNB_AllowMergeRequestProcess = false
def eNB_TargetBranch

Boris Djalal's avatar
Boris Djalal committed
36 37
pipeline {
    agent {
Boris Djalal's avatar
Save  
Boris Djalal committed
38
        label pythonExecutor 
Boris Djalal's avatar
Boris Djalal committed
39 40 41
    }
    options {
        disableConcurrentBuilds()
Boris Djalal's avatar
Boris Djalal committed
42
	timestamps()
Boris Djalal's avatar
Boris Djalal committed
43 44 45 46 47 48
        ansiColor('xterm')
    }
    stages {
        stage ('Retrieve latest from branch') {
            steps {
                script {
49
                    checkout([$class: 'GitSCM', branches: [[name: '*/gNB-nrUE-USRP']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: 'https://gitlab.eurecom.fr/oai/openairinterface5g.git']]])
Boris Djalal's avatar
Boris Djalal committed
50 51 52 53 54
                    sh "git clean -x -d -ff"
                    sh "git log -n1"
                }
            }
        }
Boris Djalal's avatar
Boris Djalal committed
55
        stage ("Print latest commit info") {
Boris Djalal's avatar
Boris Djalal committed
56
            steps {
Boris Djalal's avatar
Fix  
Boris Djalal committed
57 58 59 60 61 62 63 64
		script {
                    echo "Building on: "
                    echo "  Repository -- ${GIT_URL}"
                    echo "  Branch -- ${GIT_BRANCH}"
                    echo "  Commit -- ${GIT_COMMIT}"
                    sh "git log -n1"
                    eNB_Repository = ${GIT_URL}
	        }
Boris Djalal's avatar
Boris Djalal committed
65 66
            }
        }
Boris Djalal's avatar
Boris Djalal committed
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
        stage ("Verify Parameters") {
            steps {
                script {
                    echo '\u2705 \u001B[32mVerify Parameters\u001B[0m'
                    def allParametersPresent = true

                    // It is already too late to check it
                    if (params.pythonExecutor != null) {
                       echo "eNB CI executor node  :   ${pythonExecutor}"
                    }
                    // If not present picking a default XML file
                    if (params.pythonTestXmlFile == null) {
                        // picking default
                        testXMLFile = 'xml_files/gnb_usrp_build.xml'
                        echo "Test XML file(default):   ${testXMLFile}"
                        mainPythonAllXmlFiles += "--XMLTestFile=" + testXMLFile + " "
                    } else {
                        String[] myXmlTestSuite = testXMLFile.split("\\r?\\n")
                        for (xmlFile in myXmlTestSuite) {
                            if (fileExists("ci-scripts/" + xmlFile)) {
                                mainPythonAllXmlFiles += "--XMLTestFile=" + xmlFile + " "
                                echo "Test XML file         :   ${xmlFile}"
                            }
                        }
                    }
                    // If not present picking a default Stage Name
                    if (params.pipelineTestStageName == null) {
                        // picking default
                        testStageName = 'Template Test Stage'
                    }
Boris Djalal's avatar
Save  
Boris Djalal committed
97
                    echo "params.eNB_IPAddress = ${params.eNB_IPAddress}"
Boris Djalal's avatar
Boris Djalal committed
98 99 100
                    if (params.eNB_IPAddress == null) {
                        allParametersPresent = false
                    }
Boris Djalal's avatar
Save  
Boris Djalal committed
101
                    echo "params.UE_IPAddress = ${params.UE_IPAddress}"
Boris Djalal's avatar
Boris Djalal committed
102 103 104
                    if (params.UE_IPAddress == null) {
                        allParametersPresent = false
                    }
Boris Djalal's avatar
Save  
Boris Djalal committed
105
                    echo "params.eNB_SourceCodePath = ${params.eNB_SourceCodePath}"
Boris Djalal's avatar
Boris Djalal committed
106 107 108
                    if (params.eNB_SourceCodePath == null) {
                        allParametersPresent = false
                    }
Boris Djalal's avatar
Save  
Boris Djalal committed
109
                    echo "params.eNB_Credentials = ${params.eNB_Credentials}"
Boris Djalal's avatar
Boris Djalal committed
110 111
                    if (params.eNB_Credentials == null) {
                        allParametersPresent = false
Boris Djalal's avatar
Save  
Boris Djalal committed
112 113
                    }
                    echo "params.UE_Credentials = ${params.UE_Credentials}"
Boris Djalal's avatar
Boris Djalal committed
114 115 116
                    if (params.UE_Credentials == null) {
                        allParametersPresent = false
                    }
Boris Djalal's avatar
Save  
Boris Djalal committed
117
                    echo "params.eNB_Repository = ${params.eNB_Repository}"
Boris Djalal's avatar
Boris Djalal committed
118
                    if (params.eNB_Repository == null) {
Boris Djalal's avatar
Save  
Boris Djalal committed
119
                        eNB_Repository = ${GIT_URL} 
Boris Djalal's avatar
Boris Djalal committed
120 121 122 123 124 125 126 127 128 129 130 131 132 133
                    } else {
                        eNB_Repository = params.eNB_Repository
                    }
                    if (allParametersPresent) {
                        echo "All parameters are present"
                        sh "git fetch"
                        sh "git checkout -f ${eNB_CommitID}"
                    } else {
                        echo "Some parameters are missing"
                        sh "./ci-scripts/fail.sh"
                    }
                }
            }
        }
Boris Djalal's avatar
Save  
Boris Djalal committed
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148

        stage ("Build and Test") {
            steps {
                script {
                    dir ('ci-scripts') {
                        echo "\u2705 \u001B[32m${testStageName}\u001B[0m"
                        withCredentials([
                            [$class: 'UsernamePasswordMultiBinding', credentialsId: "${params.eNB_Credentials}", usernameVariable: 'eNB_Username', passwordVariable: 'eNB_Password'],
                            [$class: 'UsernamePasswordMultiBinding', credentialsId: "${params.UE_Credentials}", usernameVariable: 'UE_Username', passwordVariable: 'UE_Password']
                        ]) {
                            sh "python3 main.py --mode=InitiateHtml --eNBRepository=${eNB_Repository} --eNBBranch=${eNB_Branch} --eNBCommitID=${eNB_CommitID} --eNB_AllowMerge=${eNB_AllowMergeRequestProcess} --eNBTargetBranch=${eNB_TargetBranch} --ADBIPAddress=${params.ADB_IPAddress} --ADBUserName=${ADB_Username} --ADBPassword=${ADB_Password} --eNBIPAddress=127.0.0.1 --eNBUserName=carabe --eNBPassword=${eNB_Password} ${mainPythonAllXmlFiles}"
                            String[] myXmlTestSuite = testXMLFile.split("\\r?\\n")
                            for (xmlFile in myXmlTestSuite) {
                            if (fileExists(xmlFile)) {
                                try {
Boris Djalal's avatar
Save  
Boris Djalal committed
149
                                    sh "python3 main.py --mode=TesteNB --eNBIPAddress=${params.eNB_IPAddress} --eNBUserName=${eNB_Username} --eNBPassword=${eNB_Password} --eNBBranch=${eNB_Branch} --eNBSourceCodePath=${params.eNB_SourceCodePath} --eNBRepository=${eNB_Repository} --eNBCommitID=${eNB_CommitID} --ADBIPAddress=${params.ADB_IPAddress} --EPCIPAddress=${params.EPC_IPAddress} --XMLTestFile=${xmlFile}"
Boris Djalal's avatar
Save  
Boris Djalal committed
150 151 152 153 154 155 156 157 158 159 160 161
                                } catch (Exception e) {
                                    currentBuild.result = 'FAILURE'
                                    buildStageStatus = false
                                }
                            }
                            }
                            sh "python3 main.py --mode=FinalizeHtml --finalStatus=${buildStageStatus} --eNBIPAddress=${params.eNB_IPAddress} --eNBUserName=${eNB_Username} --eNBPassword=${eNB_Password}"
                        }
                    }
                }
            }
        }
Boris Djalal's avatar
Save  
Boris Djalal committed
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190

        stage ("Terminate") {
            parallel {
                stage('Terminate NR UE') {
                    steps {
                        echo '\u2705 \u001B[32mTerminate UE\u001B[0m'
                    }
                    post {
                        success {
                            script {
                                termStatusArray[termUE] = true
                            }
                        }
                    }
                }
                stage('Terminate NR eNB') {
                    steps {
                        echo '\u2705 \u001B[32mTerminate eNB\u001B[0m'
                    }
                    post {
                        success {
                            script {
                                termStatusArray[termENB] = true
                            }
                        }
                    }
                }
            }
        }
Boris Djalal's avatar
Boris Djalal committed
191
    }
192
}
Boris Djalal's avatar
Boris Djalal committed
193