blob: 74fa88fb0ca21d9765e695d58c01178bd31524b6 [file] [log] [blame]
Joey Armstrong775a20f2022-12-02 12:55:43 -05001#!/usr/bin/env groovy
2// -----------------------------------------------------------------------
3// -----------------------------------------------------------------------
4
5// -----------------------------------------------------------------------
6// -----------------------------------------------------------------------
7def getIam(String func)
8{
9 String src = 'vars/getVolthaCode.groovy'
10 String iam = [src, func].join('::')
11 return iam
12}
13
Matteo Scandolo42f6e572021-01-25 15:11:34 -080014// TODO the 3 stages are very similar, most of the code can be shared
15
Joey Armstrong775a20f2022-12-02 12:55:43 -050016def wrapped(Map config)
17{
18 def defaultConfig = [
19 branch: "master",
20 gerritProject: "",
21 gerritRefspec: "",
22 volthaSystemTestsChange: "",
23 volthaHelmChartsChange: "",
24 ]
25
26 def cfg = defaultConfig + config
Matteo Scandolo42f6e572021-01-25 15:11:34 -080027
Joey Armstrong775a20f2022-12-02 12:55:43 -050028 println "Downloading VOLTHA code with the following parameters: ${cfg}."
Matteo Scandolo42f6e572021-01-25 15:11:34 -080029
Joey Armstrong775a20f2022-12-02 12:55:43 -050030 stage('Download Patch')
31 {
32 frequent_repos = [
33 '',
34 'voltha-system-tests',
35 'voltha-helm-charts',
36 ]
Matteo Scandolo42f6e572021-01-25 15:11:34 -080037
Joey Armstrong775a20f2022-12-02 12:55:43 -050038 // We are always downloading those repos, if the patch under test is in one of those
39 // just checkout the patch, no need to clone it again
Joey Armstrongacb44422022-12-21 06:15:59 -050040 if (cfg.gerritProject == '')
41 {
42 // Revisit:
43 // gerritProject should be defined. Ignore when empty was likely
44 // added to support manually re-running a job when repo values
45 // may not be defined.
46 // Unfortunately the conditional can also inadvertently bypass
47 // checkout during an error condition.
48 // Case: when cfg= is invalid due to a jenkins hiccup.
49 }
50 elseif (!(cfg.gerritProject in frequent_repos))
Joey Armstrong775a20f2022-12-02 12:55:43 -050051 {
52 repo_project = "https://gerrit.opencord.org/${cfg.gerritProject}"
53
54 checkout([
55 $class: 'GitSCM',
56 userRemoteConfigs: [[ url:repo_project ]],
57 branches: [[ name: "${cfg.branch}", ]],
58 extensions: [
59 [$class: 'WipeWorkspace'],
60 [$class: 'RelativeTargetDirectory', relativeTargetDir: "${cfg.gerritProject}"],
61 [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false],
62 ],
63 ])
Matteo Scandolo42f6e572021-01-25 15:11:34 -080064
Joey Armstrong775a20f2022-12-02 12:55:43 -050065 sh """
Matteo Scandolo42f6e572021-01-25 15:11:34 -080066 pushd $WORKSPACE/${cfg.gerritProject}
Joey Armstrong775a20f2022-12-02 12:55:43 -050067 git fetch "$repo_project" ${cfg.gerritRefspec} && git checkout FETCH_HEAD
68
69 echo "Currently on commit: \n"
70 git log -1 --oneline
71 popd
72 """
73 }
74 }
75
76 stage('Clone voltha-system-tests')
77 {
78 repo_vst = 'https://gerrit.opencord.org/voltha-system-tests'
79
80 checkout([
81 $class: 'GitSCM',
Joey Armstrongea6aaa92022-12-19 19:00:46 -050082 userRemoteConfigs: [[ url:repo_vst ]],
Joey Armstrong775a20f2022-12-02 12:55:43 -050083 branches: [[ name: "${cfg.branch}", ]],
84 extensions: [
85 [$class: 'WipeWorkspace'],
86 [$class: 'RelativeTargetDirectory', relativeTargetDir: "voltha-system-tests"],
87 [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false],
88 ],
89 ])
90
91 if (cfg.volthaSystemTestsChange != '' && cfg.gerritProject != 'voltha-system-tests')
92 {
93 sh """
94 cd "$WORKSPACE/voltha-system-tests"
95 git fetch "${repo_vst}" ${cfg.volthaSystemTestsChange} && git checkout FETCH_HEAD
96 """
97 }
98 else if (cfg.gerritProject == 'voltha-system-tests') {
99 sh """
100 pushd "$WORKSPACE/${cfg.gerritProject}"
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800101 git fetch https://gerrit.opencord.org/${cfg.gerritProject} ${cfg.gerritRefspec} && git checkout FETCH_HEAD
102
103 echo "Currently on commit: \n"
104 git log -1 --oneline
105 popd
106 """
Joey Armstrong775a20f2022-12-02 12:55:43 -0500107 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800108 }
Joey Armstrong775a20f2022-12-02 12:55:43 -0500109
110 stage('Clone voltha-helm-charts')
111 {
112 repo_vhc = 'https://gerrit.opencord.org/voltha-helm-charts'
113
114 checkout([
115 $class: 'GitSCM',
116 userRemoteConfigs: [[ url:repo_vhc ]],
117 branches: [[ name: "${cfg.branch}", ]],
118 extensions: [
119 [$class: 'WipeWorkspace'],
120 [$class: 'RelativeTargetDirectory', relativeTargetDir: "voltha-helm-charts"],
121 [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false],
122 ],
123 ])
124
125 if (cfg.volthaHelmChartsChange != '' && cfg.gerritProject != 'voltha-helm-charts') {
126 sh """
127 cd "$WORKSPACE/voltha-helm-charts"
128 git fetch "$repo_vhc" ${cfg.volthaHelmChartsChange} && git checkout FETCH_HEAD
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800129 """
Joey Armstrong775a20f2022-12-02 12:55:43 -0500130 }
131 else if (cfg.gerritProject == 'voltha-helm-charts') {
132 sh """
133 pushd "$WORKSPACE/${cfg.gerritProject}"
134 git fetch "https://gerrit.opencord.org/${cfg.gerritProject}" ${cfg.gerritRefspec} && git checkout FETCH_HEAD
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800135
136 echo "Currently on commit: \n"
137 git log -1 --oneline
138 popd
139 """
Joey Armstrong775a20f2022-12-02 12:55:43 -0500140 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800141 }
Joey Armstrong775a20f2022-12-02 12:55:43 -0500142}
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800143
Joey Armstrong775a20f2022-12-02 12:55:43 -0500144// -----------------------------------------------------------------------
145// -----------------------------------------------------------------------
146def call(Map config)
147{
148 String iam = getIam('main')
149 Boolean debug = false
150
151 if (debug)
152 {
153 println("** ${iam}: ENTER")
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800154 }
Joey Armstrong775a20f2022-12-02 12:55:43 -0500155
156 if (!config) {
157 config = [:]
158 }
159
160 try
161 {
162 wrapped(config)
163 }
164 catch (Exception err)
165 {
166 println("** ${iam}: EXCEPTION ${err}")
167 throw err
168 }
169 finally
170 {
171 if (debug)
172 {
173 println("** ${iam}: LEAVE")
174 }
175 }
176
177 return
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800178}