Jeremy Ronquillo | 659f668 | 2020-04-16 13:18:24 -0700 | [diff] [blame] | 1 | // Copyright 2020-present Open Networking Foundation |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | // comac-in-a-box-github build+test |
| 16 | // steps taken from https://guide.opencord.org/profiles/comac/install/ciab.html |
| 17 | |
| 18 | docker_tag = "" |
| 19 | abbreviated_commit_hash = "" |
| 20 | |
| 21 | pipeline { |
| 22 | |
| 23 | /* no label, executor is determined by JJB */ |
| 24 | agent { |
| 25 | label "${params.buildNode}" |
| 26 | } |
| 27 | |
| 28 | options { |
| 29 | timeout(time: 1, unit: 'HOURS') |
| 30 | } |
| 31 | |
| 32 | environment { |
| 33 | |
| 34 | omec_cp = "$HOME/cord/helm-charts/omec/omec-control-plane/values.yaml" |
| 35 | omec_dp = "$HOME/cord/helm-charts/omec/omec-data-plane/values.yaml" |
| 36 | } |
| 37 | |
| 38 | stages { |
| 39 | stage ("Environment Setup"){ |
| 40 | steps { |
| 41 | sh label: 'Clean Logs', script: """ |
| 42 | rm -rf logs/ |
| 43 | """ |
| 44 | sh label: 'Run COMAC-in-a-box reset-test', script: """ |
| 45 | echo $HOME |
| 46 | cd $HOME/automation-tools/comac-in-a-box/ |
| 47 | sudo make reset-test |
| 48 | """ |
| 49 | sh label: 'Cleanup Docker Images', script: ''' |
| 50 | sudo docker rmi -f $(sudo docker images --format '{{.Repository}} {{.ID}}' | grep 'none' | awk '{print $2}') || true |
| 51 | sudo docker rmi -f $(sudo docker images --format '{{.Repository}}:{{.Tag}}' | grep 'openmme') || true |
| 52 | sudo docker rmi -f $(sudo docker images --format '{{.Repository}}:{{.Tag}}' | grep 'ngic') || true |
| 53 | sudo docker rmi -f $(sudo docker images --format '{{.Repository}}:{{.Tag}}' | grep 'c3po') || true |
| 54 | ''' |
| 55 | sh label: 'helm-charts Repo Fresh Clone', script: """ |
| 56 | cd $HOME/cord/ |
| 57 | sudo rm -rf helm-charts/ |
| 58 | git clone https://gerrit.opencord.org/helm-charts |
| 59 | """ |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | stage ("Build Local Docker Image"){ |
| 64 | steps { |
| 65 | script { |
| 66 | if (params.ghprbPullId == ""){ |
| 67 | docker_tag = "jenkins_debug" |
| 68 | } else { |
| 69 | pull_request_num = "PR_${params.ghprbPullId}" |
| 70 | abbreviated_commit_hash = params.ghprbActualCommit.substring(0, 7) |
| 71 | docker_tag = "${params.branch}-${pull_request_num}-${abbreviated_commit_hash}" |
| 72 | } |
| 73 | } |
| 74 | sh label: 'Clone repo', script: """ |
| 75 | rm -rf ${params.project} |
| 76 | if [ "${params.project}" = "c3po" ] |
| 77 | then |
| 78 | git clone https://github.com/omec-project/${params.project} --recursive |
| 79 | else |
| 80 | git clone https://github.com/omec-project/${params.project} |
| 81 | fi |
| 82 | cd ${params.project} |
| 83 | if [ ! -z "${params.ghprbPullId}" ] |
| 84 | then |
| 85 | echo "Checking out GitHub Pull Request: ${params.ghprbPullId}" |
| 86 | git fetch origin pull/${params.ghprbPullId}/head && git checkout FETCH_HEAD |
| 87 | else |
| 88 | echo "GERRIT_REFSPEC not provided. Checking out target branch." |
| 89 | git checkout ${params.branch} |
| 90 | fi |
| 91 | sudo make DOCKER_TAG=${docker_tag} docker-build |
| 92 | """ |
| 93 | |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | stage ("Change Helm-Charts Docker Tags"){ |
| 98 | steps { |
| 99 | sh label: 'Change Helm-Charts Docker Tags', script: """ |
| 100 | if [ "${params.project}" = "c3po" ] |
| 101 | then |
| 102 | sed -i "s;hssdb: docker.*;hssdb: \\"c3po-hssdb:${docker_tag}\\";" ${omec_cp} |
| 103 | sed -i "s;hss: .*;hss: \\"c3po-hss:${docker_tag}\\";" ${omec_cp} |
| 104 | echo "Changed hssdb and hss tag: ${docker_tag}" |
| 105 | elif [ "${params.project}" = "openmme" ] |
| 106 | then |
| 107 | sed -i "s;mme: .*;mme: \\"openmme:${docker_tag}\\";" ${omec_cp} |
| 108 | echo "Changed mme tag: ${docker_tag}" |
| 109 | elif [ "${params.project}" = "Nucleus" ] |
| 110 | then |
| 111 | sed -i "s;mme: .*;mme: \\"openmme:${docker_tag}\\";" ${omec_cp} # nucleus shares the same docker name as openmme. |
| 112 | echo "Changed mme tag: ${docker_tag}" |
| 113 | elif [ "${params.project}" = "ngic-rtc" ] |
| 114 | then |
| 115 | sed -i "s;spgwc: .*;spgwc: \\"ngic-cp:${docker_tag}\\";" ${omec_cp} |
| 116 | sed -i "s;spgwu: .*;spgwu: \\"ngic-dp:${docker_tag}-debug\\";" ${omec_dp} |
| 117 | echo "Changed spgwc and spgwu tag: ${docker_tag}" |
| 118 | else |
| 119 | echo "The project ${params.project} is not supported. Aborting job." |
| 120 | exit 1 |
| 121 | fi |
| 122 | |
| 123 | echo "omec_cp:" |
| 124 | cat "${omec_cp}" |
| 125 | |
| 126 | echo "omec_dp:" |
| 127 | cat "${omec_dp}" |
| 128 | """ |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | stage ("Run COMAC-in-a-box"){ |
| 133 | steps { |
| 134 | script{ |
| 135 | try{ |
| 136 | sh label: 'Run Makefile', script: """ |
| 137 | cd $HOME/automation-tools/comac-in-a-box/ |
| 138 | sudo make reset-test |
| 139 | sudo make test |
| 140 | """ |
| 141 | } finally { |
| 142 | sh label: 'Archive Logs', script: ''' |
| 143 | mkdir logs |
| 144 | mkdir logs/pods |
| 145 | kubectl get pods -n omec > logs/kubectl_get_pods_omec.log |
| 146 | for pod in $(kubectl get pods -n omec | awk '{print $1}' | tail -n +2) |
| 147 | do |
| 148 | kubectl logs -n omec $pod --all-containers > logs/pods/$pod.log || true |
| 149 | done |
| 150 | ''' |
| 151 | archiveArtifacts artifacts: "logs/**/*.log", allowEmptyArchive: true |
| 152 | } |
| 153 | } |
| 154 | } |
| 155 | } |
| 156 | } |
| 157 | } |