blob: fc4c7221271e4face26a4fa50c1c5a8a704063c2 [file] [log] [blame]
Joey Armstrong775a20f2022-12-02 12:55:43 -05001#!/usr/bin/env groovy
2// -----------------------------------------------------------------------
Joey Armstrongaf679da2023-01-31 14:22:41 -05003// Copyright 2021-2023 Open Networking Foundation (ONF) and the ONF Contributors
4//
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
Matteo Scandolo42f6e572021-01-25 15:11:34 -080027// TODO the 3 stages are very similar, most of the code can be shared
28
Joey Armstrong775a20f2022-12-02 12:55:43 -050029def wrapped(Map config)
30{
31 def defaultConfig = [
32 branch: "master",
33 gerritProject: "",
34 gerritRefspec: "",
35 volthaSystemTestsChange: "",
36 volthaHelmChartsChange: "",
37 ]
38
39 def cfg = defaultConfig + config
Matteo Scandolo42f6e572021-01-25 15:11:34 -080040
Joey Armstrong775a20f2022-12-02 12:55:43 -050041 println "Downloading VOLTHA code with the following parameters: ${cfg}."
Matteo Scandolo42f6e572021-01-25 15:11:34 -080042
Joey Armstrong775a20f2022-12-02 12:55:43 -050043 stage('Download Patch')
44 {
45 frequent_repos = [
46 '',
47 'voltha-system-tests',
48 'voltha-helm-charts',
49 ]
Matteo Scandolo42f6e572021-01-25 15:11:34 -080050
Joey Armstrong775a20f2022-12-02 12:55:43 -050051 // We are always downloading those repos, if the patch under test is in one of those
52 // just checkout the patch, no need to clone it again
Joey Armstrongacb44422022-12-21 06:15:59 -050053 if (cfg.gerritProject == '')
54 {
55 // Revisit:
56 // gerritProject should be defined. Ignore when empty was likely
57 // added to support manually re-running a job when repo values
58 // may not be defined.
59 // Unfortunately the conditional can also inadvertently bypass
60 // checkout during an error condition.
61 // Case: when cfg= is invalid due to a jenkins hiccup.
62 }
Joey Armstrongd0fd3d62022-12-21 15:47:39 -050063 else if (!(cfg.gerritProject in frequent_repos))
Joey Armstrong775a20f2022-12-02 12:55:43 -050064 {
65 repo_project = "https://gerrit.opencord.org/${cfg.gerritProject}"
66
67 checkout([
68 $class: 'GitSCM',
69 userRemoteConfigs: [[ url:repo_project ]],
70 branches: [[ name: "${cfg.branch}", ]],
71 extensions: [
72 [$class: 'WipeWorkspace'],
73 [$class: 'RelativeTargetDirectory', relativeTargetDir: "${cfg.gerritProject}"],
74 [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false],
75 ],
76 ])
Matteo Scandolo42f6e572021-01-25 15:11:34 -080077
Joey Armstrong775a20f2022-12-02 12:55:43 -050078 sh """
Matteo Scandolo42f6e572021-01-25 15:11:34 -080079 pushd $WORKSPACE/${cfg.gerritProject}
Joey Armstrong775a20f2022-12-02 12:55:43 -050080 git fetch "$repo_project" ${cfg.gerritRefspec} && git checkout FETCH_HEAD
81
82 echo "Currently on commit: \n"
83 git log -1 --oneline
84 popd
85 """
86 }
87 }
88
89 stage('Clone voltha-system-tests')
90 {
91 repo_vst = 'https://gerrit.opencord.org/voltha-system-tests'
92
93 checkout([
94 $class: 'GitSCM',
Joey Armstrongea6aaa92022-12-19 19:00:46 -050095 userRemoteConfigs: [[ url:repo_vst ]],
Joey Armstrong775a20f2022-12-02 12:55:43 -050096 branches: [[ name: "${cfg.branch}", ]],
97 extensions: [
98 [$class: 'WipeWorkspace'],
99 [$class: 'RelativeTargetDirectory', relativeTargetDir: "voltha-system-tests"],
100 [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false],
101 ],
102 ])
103
104 if (cfg.volthaSystemTestsChange != '' && cfg.gerritProject != 'voltha-system-tests')
105 {
106 sh """
107 cd "$WORKSPACE/voltha-system-tests"
108 git fetch "${repo_vst}" ${cfg.volthaSystemTestsChange} && git checkout FETCH_HEAD
109 """
110 }
111 else if (cfg.gerritProject == 'voltha-system-tests') {
112 sh """
113 pushd "$WORKSPACE/${cfg.gerritProject}"
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800114 git fetch https://gerrit.opencord.org/${cfg.gerritProject} ${cfg.gerritRefspec} && git checkout FETCH_HEAD
115
116 echo "Currently on commit: \n"
117 git log -1 --oneline
118 popd
119 """
Joey Armstrong775a20f2022-12-02 12:55:43 -0500120 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800121 }
Joey Armstrong775a20f2022-12-02 12:55:43 -0500122
123 stage('Clone voltha-helm-charts')
124 {
125 repo_vhc = 'https://gerrit.opencord.org/voltha-helm-charts'
126
127 checkout([
128 $class: 'GitSCM',
129 userRemoteConfigs: [[ url:repo_vhc ]],
130 branches: [[ name: "${cfg.branch}", ]],
131 extensions: [
132 [$class: 'WipeWorkspace'],
133 [$class: 'RelativeTargetDirectory', relativeTargetDir: "voltha-helm-charts"],
134 [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false],
135 ],
136 ])
137
138 if (cfg.volthaHelmChartsChange != '' && cfg.gerritProject != 'voltha-helm-charts') {
139 sh """
140 cd "$WORKSPACE/voltha-helm-charts"
141 git fetch "$repo_vhc" ${cfg.volthaHelmChartsChange} && git checkout FETCH_HEAD
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800142 """
Joey Armstrong775a20f2022-12-02 12:55:43 -0500143 }
144 else if (cfg.gerritProject == 'voltha-helm-charts') {
145 sh """
146 pushd "$WORKSPACE/${cfg.gerritProject}"
147 git fetch "https://gerrit.opencord.org/${cfg.gerritProject}" ${cfg.gerritRefspec} && git checkout FETCH_HEAD
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800148
149 echo "Currently on commit: \n"
150 git log -1 --oneline
151 popd
152 """
Joey Armstrong775a20f2022-12-02 12:55:43 -0500153 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800154 }
Joey Armstrong775a20f2022-12-02 12:55:43 -0500155}
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800156
Joey Armstrong775a20f2022-12-02 12:55:43 -0500157// -----------------------------------------------------------------------
158// -----------------------------------------------------------------------
159def call(Map config)
160{
161 String iam = getIam('main')
162 Boolean debug = false
163
164 if (debug)
165 {
166 println("** ${iam}: ENTER")
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800167 }
Joey Armstrong775a20f2022-12-02 12:55:43 -0500168
169 if (!config) {
170 config = [:]
171 }
172
173 try
174 {
175 wrapped(config)
176 }
177 catch (Exception err)
178 {
179 println("** ${iam}: EXCEPTION ${err}")
180 throw err
181 }
182 finally
183 {
184 if (debug)
185 {
186 println("** ${iam}: LEAVE")
187 }
188 }
189
190 return
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800191}
Joey Armstrongaf679da2023-01-31 14:22:41 -0500192
193// [EOF]