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