blob: 4230b9e60cbb526f90125ee513e967046abe22c5 [file] [log] [blame]
Joey Armstrong775a20f2022-12-02 12:55:43 -05001#!/usr/bin/env groovy
2// -----------------------------------------------------------------------
Joey Armstrongdef9c402024-01-30 18:05:29 -05003// Copyright 2021-2024 Open Networking Foundation (ONF) and the ONF Contributors
Joey Armstrongaf679da2023-01-31 14:22:41 -05004//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
Joey Armstrong775a20f2022-12-02 12:55:43 -050016// -----------------------------------------------------------------------
17
18// -----------------------------------------------------------------------
19// -----------------------------------------------------------------------
20def getIam(String func)
21{
22 String src = 'vars/getVolthaCode.groovy'
23 String iam = [src, func].join('::')
24 return iam
25}
26
Joey Armstrongdef9c402024-01-30 18:05:29 -050027// -----------------------------------------------------------------------
28// Intent: Log progress message
29// -----------------------------------------------------------------------
30void enter(String name) {
31 // Announce ourselves for log usability
32 String iam = getIam(name)
33 println("${iam}: ENTER")
34 return
35}
36
37// -----------------------------------------------------------------------
38// Intent: Log progress message
39// -----------------------------------------------------------------------
40void leave(String name) {
41 // Announce ourselves for log usability
42 String iam = getIam(name)
43 println("${iam}: LEAVE")
44 return
45}
46
Matteo Scandolo42f6e572021-01-25 15:11:34 -080047// TODO the 3 stages are very similar, most of the code can be shared
48
Joey Armstrongdef9c402024-01-30 18:05:29 -050049// -----------------------------------------------------------------------
50// -----------------------------------------------------------------------
Joey Armstrong775a20f2022-12-02 12:55:43 -050051def wrapped(Map config)
52{
53 def defaultConfig = [
Joey Armstrongdef9c402024-01-30 18:05:29 -050054 branch: "master",
55 gerritProject: "",
56 gerritRefspec: "",
57 volthaSystemTestsChange: "",
58 volthaHelmChartsChange: "",
Joey Armstrong775a20f2022-12-02 12:55:43 -050059 ]
Joey Armstrongdef9c402024-01-30 18:05:29 -050060
Joey Armstrong775a20f2022-12-02 12:55:43 -050061 def cfg = defaultConfig + config
Matteo Scandolo42f6e572021-01-25 15:11:34 -080062
Joey Armstrongdef9c402024-01-30 18:05:29 -050063 println("""
64
65** -----------------------------------------------------------------------
66** Downloading VOLTHA code with the following parameters:
67** ${cfg}
68** -----------------------------------------------------------------------
69""")
Matteo Scandolo42f6e572021-01-25 15:11:34 -080070
Joey Armstrong775a20f2022-12-02 12:55:43 -050071 stage('Download Patch')
72 {
Joey Armstrongdef9c402024-01-30 18:05:29 -050073 frequent_repos = [
74 '',
75 'voltha-system-tests',
76 'voltha-helm-charts',
77 ]
Matteo Scandolo42f6e572021-01-25 15:11:34 -080078
Eric Ball3f0cec32024-10-10 17:16:03 -070079 // We are always downloading those repos, if the patch under test is in
80 // one of those just checkout the patch, no need to clone it again
Joey Armstrongdef9c402024-01-30 18:05:29 -050081 if (cfg.gerritProject == '')
82 {
83 // Revisit:
84 // gerritProject should be defined. Ignore when empty was likely
85 // added to support manually re-running a job when repo values
86 // may not be defined.
87 // Unfortunately the conditional can also inadvertently bypass
88 // checkout during an error condition.
89 // Case: when cfg= is invalid due to a jenkins hiccup.
90 }
Eric Ball3f0cec32024-10-10 17:16:03 -070091 else if (params.GERRIT_PROJECT == "onf-make")
92 {
93 // When testing onf-make, the tests are kicked off from the onf-make
94 // repo, so the GERRIT_PROJECT and GERRIT_PATCHSET_REVISION params
95 // will carry the data of what we want the submodule to be.
96 // However, the gerritProject is overridden, so that we can pull
97 // in another repo and run the tests to make sure that they work
98 // with the code changes to onf-make.
99 repo_project = "https://gerrit.opencord.org/${cfg.gerritProject}"
100
101 checkout([
102 $class: 'GitSCM',
103 userRemoteConfigs: [[ url:repo_project ]],
104 branches: [[ name: "${cfg.branch}", ]],
105 extensions: [
106 [$class: 'WipeWorkspace'],
107 [$class: 'RelativeTargetDirectory', relativeTargetDir: "${cfg.gerritProject}"],
108 [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false],
109 submodule(recursiveSubmodules: true, reference: "${params.GERRIT_PATCHSET_REVISION}"),
110 ],
111 ])
112
113 sh("""pushd $WORKSPACE/${cfg.gerritProject}
114 git fetch "$repo_project" ${cfg.gerritRefspec} && git checkout FETCH_HEAD
115
116 echo "Currently on commit: \n"
117 git log -1 --oneline
118 popd
119 """)
120 }
Joey Armstrongdef9c402024-01-30 18:05:29 -0500121 else if (!(cfg.gerritProject in frequent_repos))
122 {
123 repo_project = "https://gerrit.opencord.org/${cfg.gerritProject}"
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800124
Joey Armstrongdef9c402024-01-30 18:05:29 -0500125 checkout([
126 $class: 'GitSCM',
127 userRemoteConfigs: [[ url:repo_project ]],
128 branches: [[ name: "${cfg.branch}", ]],
129 extensions: [
130 [$class: 'WipeWorkspace'],
131 [$class: 'RelativeTargetDirectory', relativeTargetDir: "${cfg.gerritProject}"],
132 [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false],
133 ],
134 ])
135
Eric Ball3f0cec32024-10-10 17:16:03 -0700136 sh("""pushd $WORKSPACE/${cfg.gerritProject}
137 git fetch "$repo_project" ${cfg.gerritRefspec} && git checkout FETCH_HEAD
Joey Armstrong775a20f2022-12-02 12:55:43 -0500138
Eric Ball3f0cec32024-10-10 17:16:03 -0700139 echo "Currently on commit: \n"
140 git log -1 --oneline
141 popd
142 """)
Joey Armstrongdef9c402024-01-30 18:05:29 -0500143 }
Joey Armstrong775a20f2022-12-02 12:55:43 -0500144 }
145
Joey Armstrongdef9c402024-01-30 18:05:29 -0500146 // -----------------------------------------------------------------------
147 // -----------------------------------------------------------------------
Joey Armstrong775a20f2022-12-02 12:55:43 -0500148 stage('Clone voltha-system-tests')
Joey Armstrongdef9c402024-01-30 18:05:29 -0500149 {
Joey Armstrong93cd4942024-01-30 18:45:46 -0500150 enter("Clone voltha-system-tests @ BRANCH=[${cfg.branch}]")
Joey Armstrongdef9c402024-01-30 18:05:29 -0500151 println("""
Joey Armstrong775a20f2022-12-02 12:55:43 -0500152
Joey Armstrongdef9c402024-01-30 18:05:29 -0500153** -----------------------------------------------------------------------
154** Clone voltha-system-tests
155** -----------------------------------------------------------------------
156""")
157 repo_vst = 'https://gerrit.opencord.org/voltha-system-tests'
Joey Armstrong775a20f2022-12-02 12:55:43 -0500158
Joey Armstrongdef9c402024-01-30 18:05:29 -0500159 checkout([
160 $class: 'GitSCM',
161 userRemoteConfigs: [[ url:repo_vst ]],
162 branches: [[ name: "${cfg.branch}", ]],
163 extensions: [
164 [$class: 'WipeWorkspace'],
165 [$class: 'RelativeTargetDirectory', relativeTargetDir: "voltha-system-tests"],
166 [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false],
167 ],
168 ])
169
170 if (cfg.volthaSystemTestsChange != '' && cfg.gerritProject != 'voltha-system-tests')
171 {
172 enter("git fetch repo_vst=[${repo_vst}]")
173
174 sh """
Joey Armstrong775a20f2022-12-02 12:55:43 -0500175 cd "$WORKSPACE/voltha-system-tests"
176 git fetch "${repo_vst}" ${cfg.volthaSystemTestsChange} && git checkout FETCH_HEAD
177 """
Joey Armstrongdef9c402024-01-30 18:05:29 -0500178 leave("git fetch repo_vst=[${repo_vst}]")
179 }
180 else if (cfg.gerritProject == 'voltha-system-tests') {
181 enter("git fetch https://${cfg.gerritProject}")
182
183 sh("""
Joey Armstrong775a20f2022-12-02 12:55:43 -0500184 pushd "$WORKSPACE/${cfg.gerritProject}"
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800185 git fetch https://gerrit.opencord.org/${cfg.gerritProject} ${cfg.gerritRefspec} && git checkout FETCH_HEAD
186
187 echo "Currently on commit: \n"
188 git log -1 --oneline
189 popd
Joey Armstrongdef9c402024-01-30 18:05:29 -0500190 """)
191 leave("git fetch https://${cfg.gerritProject}")
192 }
193
Joey Armstrong93cd4942024-01-30 18:45:46 -0500194 leave("Clone voltha-system-tests @ BRANCH=[${cfg.branch}]")
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800195 }
Joey Armstrong775a20f2022-12-02 12:55:43 -0500196
Joey Armstrongdef9c402024-01-30 18:05:29 -0500197 // -----------------------------------------------------------------------
198 // -----------------------------------------------------------------------
Joey Armstrong775a20f2022-12-02 12:55:43 -0500199 stage('Clone voltha-helm-charts')
200 {
Joey Armstrong93cd4942024-01-30 18:45:46 -0500201 enter("Clone voltha-helm-charts @ BRANCH=[${cfg.branch}]")
Joey Armstrongdef9c402024-01-30 18:05:29 -0500202 repo_vhc = 'https://gerrit.opencord.org/voltha-helm-charts'
Joey Armstrong775a20f2022-12-02 12:55:43 -0500203
Joey Armstrongdef9c402024-01-30 18:05:29 -0500204 checkout([
205 $class: 'GitSCM',
206 userRemoteConfigs: [[ url:repo_vhc ]],
207 branches: [[ name: "${cfg.branch}", ]],
208 extensions: [
209 [$class: 'WipeWorkspace'],
210 [$class: 'RelativeTargetDirectory', relativeTargetDir: "voltha-helm-charts"],
211 [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false],
212 ],
213 ])
Joey Armstrong775a20f2022-12-02 12:55:43 -0500214
Joey Armstrongdef9c402024-01-30 18:05:29 -0500215 if (cfg.volthaHelmChartsChange != '' && cfg.gerritProject != 'voltha-helm-charts') {
216 enter("git fetch repo_vhc=[$repo_vhc]")
217 sh """
Joey Armstrong775a20f2022-12-02 12:55:43 -0500218 cd "$WORKSPACE/voltha-helm-charts"
219 git fetch "$repo_vhc" ${cfg.volthaHelmChartsChange} && git checkout FETCH_HEAD
Joey Armstrongdaa1f0a2024-04-03 18:07:59 -0400220 """
Joey Armstrongdef9c402024-01-30 18:05:29 -0500221 leave("git fetch repo_vhc=[$repo_vhc]")
222 }
223 else if (cfg.gerritProject == 'voltha-helm-charts') {
224 enter('cfg.gerritProject == voltha-helm-charts')
225 sh """
Joey Armstrong775a20f2022-12-02 12:55:43 -0500226 pushd "$WORKSPACE/${cfg.gerritProject}"
227 git fetch "https://gerrit.opencord.org/${cfg.gerritProject}" ${cfg.gerritRefspec} && git checkout FETCH_HEAD
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800228
229 echo "Currently on commit: \n"
230 git log -1 --oneline
231 popd
232 """
Joey Armstrongdef9c402024-01-30 18:05:29 -0500233 leave('cfg.gerritProject == voltha-helm-charts')
234 }
235
Joey Armstrong93cd4942024-01-30 18:45:46 -0500236 leave("Clone voltha-helm-charts @ BRANCH=[${cfg.branch}]")
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800237 }
Joey Armstrong775a20f2022-12-02 12:55:43 -0500238}
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800239
Joey Armstrong775a20f2022-12-02 12:55:43 -0500240// -----------------------------------------------------------------------
241// -----------------------------------------------------------------------
242def call(Map config)
243{
244 String iam = getIam('main')
Joey Armstrongdef9c402024-01-30 18:05:29 -0500245 Boolean debug = true
Joey Armstrong775a20f2022-12-02 12:55:43 -0500246
Joey Armstrongdef9c402024-01-30 18:05:29 -0500247 if (debug) {
248 println("** ${iam}: ENTER")
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800249 }
Joey Armstrong775a20f2022-12-02 12:55:43 -0500250
Joey Armstrongdef9c402024-01-30 18:05:29 -0500251 config ?: [:]
Joey Armstrong775a20f2022-12-02 12:55:43 -0500252
253 try
254 {
Joey Armstrongdef9c402024-01-30 18:05:29 -0500255 wrapped(config)
Joey Armstrong775a20f2022-12-02 12:55:43 -0500256 }
257 catch (Exception err)
258 {
Joey Armstrongdef9c402024-01-30 18:05:29 -0500259 println("** ${iam}: EXCEPTION ${err}")
260 throw err
Joey Armstrong775a20f2022-12-02 12:55:43 -0500261 }
262 finally
263 {
Joey Armstrongdef9c402024-01-30 18:05:29 -0500264 if (debug)
265 {
266 println("** ${iam}: LEAVE")
267 }
Joey Armstrong775a20f2022-12-02 12:55:43 -0500268 }
269
270 return
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800271}
Joey Armstrongaf679da2023-01-31 14:22:41 -0500272
273// [EOF]