blob: aecb30dee5261d28337bd520686bbc7dfa1d8798 [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
Joey Armstrongdef9c402024-01-30 18:05:29 -050079 // We are always downloading those repos, if the patch under test is in one of those
80 // just checkout the patch, no need to clone it again
81 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 }
91 else if (!(cfg.gerritProject in frequent_repos))
92 {
93 repo_project = "https://gerrit.opencord.org/${cfg.gerritProject}"
Matteo Scandolo42f6e572021-01-25 15:11:34 -080094
Joey Armstrongdef9c402024-01-30 18:05:29 -050095 checkout([
96 $class: 'GitSCM',
97 userRemoteConfigs: [[ url:repo_project ]],
98 branches: [[ name: "${cfg.branch}", ]],
99 extensions: [
100 [$class: 'WipeWorkspace'],
101 [$class: 'RelativeTargetDirectory', relativeTargetDir: "${cfg.gerritProject}"],
102 [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false],
103 ],
104 ])
105
106 sh("""
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800107 pushd $WORKSPACE/${cfg.gerritProject}
Joey Armstrong775a20f2022-12-02 12:55:43 -0500108 git fetch "$repo_project" ${cfg.gerritRefspec} && git checkout FETCH_HEAD
109
110 echo "Currently on commit: \n"
111 git log -1 --oneline
112 popd
Joey Armstrongdef9c402024-01-30 18:05:29 -0500113 """)
114 }
Joey Armstrong775a20f2022-12-02 12:55:43 -0500115 }
116
Joey Armstrongdef9c402024-01-30 18:05:29 -0500117 // -----------------------------------------------------------------------
118 // -----------------------------------------------------------------------
Joey Armstrong775a20f2022-12-02 12:55:43 -0500119 stage('Clone voltha-system-tests')
Joey Armstrongdef9c402024-01-30 18:05:29 -0500120 {
Joey Armstrong93cd4942024-01-30 18:45:46 -0500121 enter("Clone voltha-system-tests @ BRANCH=[${cfg.branch}]")
Joey Armstrongdef9c402024-01-30 18:05:29 -0500122 println("""
Joey Armstrong775a20f2022-12-02 12:55:43 -0500123
Joey Armstrongdef9c402024-01-30 18:05:29 -0500124** -----------------------------------------------------------------------
125** Clone voltha-system-tests
126** -----------------------------------------------------------------------
127""")
128 repo_vst = 'https://gerrit.opencord.org/voltha-system-tests'
Joey Armstrong775a20f2022-12-02 12:55:43 -0500129
Joey Armstrongdef9c402024-01-30 18:05:29 -0500130 checkout([
131 $class: 'GitSCM',
132 userRemoteConfigs: [[ url:repo_vst ]],
133 branches: [[ name: "${cfg.branch}", ]],
134 extensions: [
135 [$class: 'WipeWorkspace'],
136 [$class: 'RelativeTargetDirectory', relativeTargetDir: "voltha-system-tests"],
137 [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false],
138 ],
139 ])
140
141 if (cfg.volthaSystemTestsChange != '' && cfg.gerritProject != 'voltha-system-tests')
142 {
143 enter("git fetch repo_vst=[${repo_vst}]")
144
145 sh """
Joey Armstrong775a20f2022-12-02 12:55:43 -0500146 cd "$WORKSPACE/voltha-system-tests"
147 git fetch "${repo_vst}" ${cfg.volthaSystemTestsChange} && git checkout FETCH_HEAD
148 """
Joey Armstrongdef9c402024-01-30 18:05:29 -0500149 leave("git fetch repo_vst=[${repo_vst}]")
150 }
151 else if (cfg.gerritProject == 'voltha-system-tests') {
152 enter("git fetch https://${cfg.gerritProject}")
153
154 sh("""
Joey Armstrong775a20f2022-12-02 12:55:43 -0500155 pushd "$WORKSPACE/${cfg.gerritProject}"
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800156 git fetch https://gerrit.opencord.org/${cfg.gerritProject} ${cfg.gerritRefspec} && git checkout FETCH_HEAD
157
158 echo "Currently on commit: \n"
159 git log -1 --oneline
160 popd
Joey Armstrongdef9c402024-01-30 18:05:29 -0500161 """)
162 leave("git fetch https://${cfg.gerritProject}")
163 }
164
Joey Armstrong93cd4942024-01-30 18:45:46 -0500165 leave("Clone voltha-system-tests @ BRANCH=[${cfg.branch}]")
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800166 }
Joey Armstrong775a20f2022-12-02 12:55:43 -0500167
Joey Armstrongdef9c402024-01-30 18:05:29 -0500168 // -----------------------------------------------------------------------
169 // -----------------------------------------------------------------------
Joey Armstrong775a20f2022-12-02 12:55:43 -0500170 stage('Clone voltha-helm-charts')
171 {
Joey Armstrong93cd4942024-01-30 18:45:46 -0500172 enter("Clone voltha-helm-charts @ BRANCH=[${cfg.branch}]")
Joey Armstrongdef9c402024-01-30 18:05:29 -0500173 repo_vhc = 'https://gerrit.opencord.org/voltha-helm-charts'
Joey Armstrong775a20f2022-12-02 12:55:43 -0500174
Joey Armstrongdef9c402024-01-30 18:05:29 -0500175 checkout([
176 $class: 'GitSCM',
177 userRemoteConfigs: [[ url:repo_vhc ]],
178 branches: [[ name: "${cfg.branch}", ]],
179 extensions: [
180 [$class: 'WipeWorkspace'],
181 [$class: 'RelativeTargetDirectory', relativeTargetDir: "voltha-helm-charts"],
182 [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false],
183 ],
184 ])
Joey Armstrong775a20f2022-12-02 12:55:43 -0500185
Joey Armstrongdef9c402024-01-30 18:05:29 -0500186 if (cfg.volthaHelmChartsChange != '' && cfg.gerritProject != 'voltha-helm-charts') {
187 enter("git fetch repo_vhc=[$repo_vhc]")
188 sh """
Joey Armstrong775a20f2022-12-02 12:55:43 -0500189 cd "$WORKSPACE/voltha-helm-charts"
190 git fetch "$repo_vhc" ${cfg.volthaHelmChartsChange} && git checkout FETCH_HEAD
Joey Armstrongdaa1f0a2024-04-03 18:07:59 -0400191 """
Joey Armstrongdef9c402024-01-30 18:05:29 -0500192 leave("git fetch repo_vhc=[$repo_vhc]")
193 }
194 else if (cfg.gerritProject == 'voltha-helm-charts') {
195 enter('cfg.gerritProject == voltha-helm-charts')
196 sh """
Joey Armstrong775a20f2022-12-02 12:55:43 -0500197 pushd "$WORKSPACE/${cfg.gerritProject}"
198 git fetch "https://gerrit.opencord.org/${cfg.gerritProject}" ${cfg.gerritRefspec} && git checkout FETCH_HEAD
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800199
200 echo "Currently on commit: \n"
201 git log -1 --oneline
202 popd
203 """
Joey Armstrongdef9c402024-01-30 18:05:29 -0500204 leave('cfg.gerritProject == voltha-helm-charts')
205 }
206
Joey Armstrong93cd4942024-01-30 18:45:46 -0500207 leave("Clone voltha-helm-charts @ BRANCH=[${cfg.branch}]")
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800208 }
Joey Armstrong775a20f2022-12-02 12:55:43 -0500209}
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800210
Joey Armstrong775a20f2022-12-02 12:55:43 -0500211// -----------------------------------------------------------------------
212// -----------------------------------------------------------------------
213def call(Map config)
214{
215 String iam = getIam('main')
Joey Armstrongdef9c402024-01-30 18:05:29 -0500216 Boolean debug = true
Joey Armstrong775a20f2022-12-02 12:55:43 -0500217
Joey Armstrongdef9c402024-01-30 18:05:29 -0500218 if (debug) {
219 println("** ${iam}: ENTER")
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800220 }
Joey Armstrong775a20f2022-12-02 12:55:43 -0500221
Joey Armstrongdef9c402024-01-30 18:05:29 -0500222 config ?: [:]
Joey Armstrong775a20f2022-12-02 12:55:43 -0500223
224 try
225 {
Joey Armstrongdef9c402024-01-30 18:05:29 -0500226 wrapped(config)
Joey Armstrong775a20f2022-12-02 12:55:43 -0500227 }
228 catch (Exception err)
229 {
Joey Armstrongdef9c402024-01-30 18:05:29 -0500230 println("** ${iam}: EXCEPTION ${err}")
231 throw err
Joey Armstrong775a20f2022-12-02 12:55:43 -0500232 }
233 finally
234 {
Joey Armstrongdef9c402024-01-30 18:05:29 -0500235 if (debug)
236 {
237 println("** ${iam}: LEAVE")
238 }
Joey Armstrong775a20f2022-12-02 12:55:43 -0500239 }
240
241 return
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800242}
Joey Armstrongaf679da2023-01-31 14:22:41 -0500243
244// [EOF]