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 |
Jeremy Ronquillo | 054f81a | 2020-06-04 12:00:29 -0700 | [diff] [blame^] | 52 | sudo docker rmi -f $(sudo docker images --format '{{.Repository}}:{{.Tag}}' | grep 'nucleus') || true |
Jeremy Ronquillo | 659f668 | 2020-04-16 13:18:24 -0700 | [diff] [blame] | 53 | sudo docker rmi -f $(sudo docker images --format '{{.Repository}}:{{.Tag}}' | grep 'ngic') || true |
| 54 | sudo docker rmi -f $(sudo docker images --format '{{.Repository}}:{{.Tag}}' | grep 'c3po') || true |
| 55 | ''' |
| 56 | sh label: 'helm-charts Repo Fresh Clone', script: """ |
| 57 | cd $HOME/cord/ |
| 58 | sudo rm -rf helm-charts/ |
| 59 | git clone https://gerrit.opencord.org/helm-charts |
| 60 | """ |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | stage ("Build Local Docker Image"){ |
| 65 | steps { |
| 66 | script { |
| 67 | if (params.ghprbPullId == ""){ |
| 68 | docker_tag = "jenkins_debug" |
| 69 | } else { |
| 70 | pull_request_num = "PR_${params.ghprbPullId}" |
| 71 | abbreviated_commit_hash = params.ghprbActualCommit.substring(0, 7) |
| 72 | docker_tag = "${params.branch}-${pull_request_num}-${abbreviated_commit_hash}" |
| 73 | } |
| 74 | } |
Jeremy Ronquillo | 054f81a | 2020-06-04 12:00:29 -0700 | [diff] [blame^] | 75 | sh label: 'Clone repo, then make docker-build', script: """ |
Jeremy Ronquillo | 659f668 | 2020-04-16 13:18:24 -0700 | [diff] [blame] | 76 | rm -rf ${params.project} |
| 77 | if [ "${params.project}" = "c3po" ] |
| 78 | then |
| 79 | git clone https://github.com/omec-project/${params.project} --recursive |
| 80 | else |
| 81 | git clone https://github.com/omec-project/${params.project} |
| 82 | fi |
| 83 | cd ${params.project} |
| 84 | if [ ! -z "${params.ghprbPullId}" ] |
| 85 | then |
| 86 | echo "Checking out GitHub Pull Request: ${params.ghprbPullId}" |
| 87 | git fetch origin pull/${params.ghprbPullId}/head && git checkout FETCH_HEAD |
| 88 | else |
| 89 | echo "GERRIT_REFSPEC not provided. Checking out target branch." |
| 90 | git checkout ${params.branch} |
| 91 | fi |
| 92 | sudo make DOCKER_TAG=${docker_tag} docker-build |
| 93 | """ |
| 94 | |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | stage ("Change Helm-Charts Docker Tags"){ |
| 99 | steps { |
| 100 | sh label: 'Change Helm-Charts Docker Tags', script: """ |
| 101 | if [ "${params.project}" = "c3po" ] |
| 102 | then |
| 103 | sed -i "s;hssdb: docker.*;hssdb: \\"c3po-hssdb:${docker_tag}\\";" ${omec_cp} |
| 104 | sed -i "s;hss: .*;hss: \\"c3po-hss:${docker_tag}\\";" ${omec_cp} |
| 105 | echo "Changed hssdb and hss tag: ${docker_tag}" |
| 106 | elif [ "${params.project}" = "openmme" ] |
| 107 | then |
| 108 | sed -i "s;mme: .*;mme: \\"openmme:${docker_tag}\\";" ${omec_cp} |
| 109 | echo "Changed mme tag: ${docker_tag}" |
| 110 | elif [ "${params.project}" = "Nucleus" ] |
| 111 | then |
| 112 | sed -i "s;mme: .*;mme: \\"openmme:${docker_tag}\\";" ${omec_cp} # nucleus shares the same docker name as openmme. |
| 113 | echo "Changed mme tag: ${docker_tag}" |
| 114 | elif [ "${params.project}" = "ngic-rtc" ] |
| 115 | then |
| 116 | sed -i "s;spgwc: .*;spgwc: \\"ngic-cp:${docker_tag}\\";" ${omec_cp} |
| 117 | sed -i "s;spgwu: .*;spgwu: \\"ngic-dp:${docker_tag}-debug\\";" ${omec_dp} |
| 118 | echo "Changed spgwc and spgwu tag: ${docker_tag}" |
| 119 | else |
| 120 | echo "The project ${params.project} is not supported. Aborting job." |
| 121 | exit 1 |
| 122 | fi |
| 123 | |
| 124 | echo "omec_cp:" |
| 125 | cat "${omec_cp}" |
| 126 | |
| 127 | echo "omec_dp:" |
| 128 | cat "${omec_dp}" |
| 129 | """ |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | stage ("Run COMAC-in-a-box"){ |
| 134 | steps { |
| 135 | script{ |
| 136 | try{ |
| 137 | sh label: 'Run Makefile', script: """ |
| 138 | cd $HOME/automation-tools/comac-in-a-box/ |
| 139 | sudo make reset-test |
| 140 | sudo make test |
| 141 | """ |
| 142 | } finally { |
| 143 | sh label: 'Archive Logs', script: ''' |
| 144 | mkdir logs |
| 145 | mkdir logs/pods |
| 146 | kubectl get pods -n omec > logs/kubectl_get_pods_omec.log |
| 147 | for pod in $(kubectl get pods -n omec | awk '{print $1}' | tail -n +2) |
| 148 | do |
| 149 | kubectl logs -n omec $pod --all-containers > logs/pods/$pod.log || true |
| 150 | done |
| 151 | ''' |
| 152 | archiveArtifacts artifacts: "logs/**/*.log", allowEmptyArchive: true |
| 153 | } |
| 154 | } |
| 155 | } |
| 156 | } |
| 157 | } |
| 158 | } |