blob: 5153b6cf3d14a9b9e4800908d97033f79dc7a24d [file] [log] [blame]
Jeremy Ronquillo659f6682020-04-16 13:18:24 -07001// 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
18docker_tag = ""
19abbreviated_commit_hash = ""
20
21pipeline {
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 {
Jeremy Ronquillo8df6ef82020-06-09 09:39:45 -070033 omec_cp = "$HOME/cord/aether-helm-charts/omec/omec-control-plane/values.yaml"
34 omec_dp = "$HOME/cord/aether-helm-charts/omec/omec-data-plane/values.yaml"
Jeremy Ronquillo659f6682020-04-16 13:18:24 -070035 }
36
37 stages {
38 stage ("Environment Setup"){
39 steps {
40 sh label: 'Clean Logs', script: """
41 rm -rf logs/
42 """
43 sh label: 'Run COMAC-in-a-box reset-test', script: """
44 echo $HOME
45 cd $HOME/automation-tools/comac-in-a-box/
Jeremy Ronquillo57ef9972020-06-08 11:13:19 -070046 make reset-test
Jeremy Ronquillo659f6682020-04-16 13:18:24 -070047 """
Jeremy Ronquillo659f6682020-04-16 13:18:24 -070048 sh label: 'helm-charts Repo Fresh Clone', script: """
49 cd $HOME/cord/
Jeremy Ronquillo8df6ef82020-06-09 09:39:45 -070050 rm -rf aether-helm-charts/
51 git clone ssh://jeremyr@gerrit.opencord.org:29418/aether-helm-charts
Jeremy Ronquillo659f6682020-04-16 13:18:24 -070052 """
53 }
54 }
55
56 stage ("Build Local Docker Image"){
57 steps {
58 script {
59 if (params.ghprbPullId == ""){
60 docker_tag = "jenkins_debug"
61 } else {
62 pull_request_num = "PR_${params.ghprbPullId}"
63 abbreviated_commit_hash = params.ghprbActualCommit.substring(0, 7)
64 docker_tag = "${params.branch}-${pull_request_num}-${abbreviated_commit_hash}"
65 }
66 }
Jeremy Ronquillo054f81a2020-06-04 12:00:29 -070067 sh label: 'Clone repo, then make docker-build', script: """
Jeremy Ronquillo659f6682020-04-16 13:18:24 -070068 rm -rf ${params.project}
69 if [ "${params.project}" = "c3po" ]
70 then
71 git clone https://github.com/omec-project/${params.project} --recursive
72 else
73 git clone https://github.com/omec-project/${params.project}
74 fi
75 cd ${params.project}
76 if [ ! -z "${params.ghprbPullId}" ]
77 then
78 echo "Checking out GitHub Pull Request: ${params.ghprbPullId}"
79 git fetch origin pull/${params.ghprbPullId}/head && git checkout FETCH_HEAD
80 else
81 echo "GERRIT_REFSPEC not provided. Checking out target branch."
82 git checkout ${params.branch}
83 fi
84 sudo make DOCKER_TAG=${docker_tag} docker-build
85 """
86
87 }
88 }
89
90 stage ("Change Helm-Charts Docker Tags"){
91 steps {
92 sh label: 'Change Helm-Charts Docker Tags', script: """
93 if [ "${params.project}" = "c3po" ]
94 then
95 sed -i "s;hssdb: docker.*;hssdb: \\"c3po-hssdb:${docker_tag}\\";" ${omec_cp}
96 sed -i "s;hss: .*;hss: \\"c3po-hss:${docker_tag}\\";" ${omec_cp}
97 echo "Changed hssdb and hss tag: ${docker_tag}"
98 elif [ "${params.project}" = "openmme" ]
99 then
100 sed -i "s;mme: .*;mme: \\"openmme:${docker_tag}\\";" ${omec_cp}
101 echo "Changed mme tag: ${docker_tag}"
102 elif [ "${params.project}" = "Nucleus" ]
103 then
Jeremy Ronquillob56efea2020-06-08 09:28:26 -0700104 sed -i "s;mme: .*;mme: \\"nucleus:${docker_tag}\\";" ${omec_cp}
Jeremy Ronquillo659f6682020-04-16 13:18:24 -0700105 echo "Changed mme tag: ${docker_tag}"
106 elif [ "${params.project}" = "ngic-rtc" ]
107 then
108 sed -i "s;spgwc: .*;spgwc: \\"ngic-cp:${docker_tag}\\";" ${omec_cp}
109 sed -i "s;spgwu: .*;spgwu: \\"ngic-dp:${docker_tag}-debug\\";" ${omec_dp}
110 echo "Changed spgwc and spgwu tag: ${docker_tag}"
111 else
112 echo "The project ${params.project} is not supported. Aborting job."
113 exit 1
114 fi
Jeremy Ronquillo659f6682020-04-16 13:18:24 -0700115 """
116 }
117 }
118
119 stage ("Run COMAC-in-a-box"){
120 steps {
121 script{
122 try{
123 sh label: 'Run Makefile', script: """
124 cd $HOME/automation-tools/comac-in-a-box/
Jeremy Ronquillo57ef9972020-06-08 11:13:19 -0700125 make reset-test
126 make test
Jeremy Ronquillo659f6682020-04-16 13:18:24 -0700127 """
128 } finally {
129 sh label: 'Archive Logs', script: '''
130 mkdir logs
131 mkdir logs/pods
132 kubectl get pods -n omec > logs/kubectl_get_pods_omec.log
133 for pod in $(kubectl get pods -n omec | awk '{print $1}' | tail -n +2)
134 do
135 kubectl logs -n omec $pod --all-containers > logs/pods/$pod.log || true
136 done
137 '''
138 archiveArtifacts artifacts: "logs/**/*.log", allowEmptyArchive: true
139 }
140 }
141 }
142 }
143 }
144}