blob: d7cb445a824103bba2d725a7430b96d0b7d5c4f8 [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
40 if ( !(cfg.gerritProject in frequent_repos))
41 {
42 repo_project = "https://gerrit.opencord.org/${cfg.gerritProject}"
43
44 checkout([
45 $class: 'GitSCM',
46 userRemoteConfigs: [[ url:repo_project ]],
47 branches: [[ name: "${cfg.branch}", ]],
48 extensions: [
49 [$class: 'WipeWorkspace'],
50 [$class: 'RelativeTargetDirectory', relativeTargetDir: "${cfg.gerritProject}"],
51 [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false],
52 ],
53 ])
Matteo Scandolo42f6e572021-01-25 15:11:34 -080054
Joey Armstrong775a20f2022-12-02 12:55:43 -050055 sh """
Matteo Scandolo42f6e572021-01-25 15:11:34 -080056 pushd $WORKSPACE/${cfg.gerritProject}
Joey Armstrong775a20f2022-12-02 12:55:43 -050057 git fetch "$repo_project" ${cfg.gerritRefspec} && git checkout FETCH_HEAD
58
59 echo "Currently on commit: \n"
60 git log -1 --oneline
61 popd
62 """
63 }
64 }
65
66 stage('Clone voltha-system-tests')
67 {
68 repo_vst = 'https://gerrit.opencord.org/voltha-system-tests'
69
70 checkout([
71 $class: 'GitSCM',
72 userRemoteConfigs: [[ url:repo_url ]],
73 branches: [[ name: "${cfg.branch}", ]],
74 extensions: [
75 [$class: 'WipeWorkspace'],
76 [$class: 'RelativeTargetDirectory', relativeTargetDir: "voltha-system-tests"],
77 [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false],
78 ],
79 ])
80
81 if (cfg.volthaSystemTestsChange != '' && cfg.gerritProject != 'voltha-system-tests')
82 {
83 sh """
84 cd "$WORKSPACE/voltha-system-tests"
85 git fetch "${repo_vst}" ${cfg.volthaSystemTestsChange} && git checkout FETCH_HEAD
86 """
87 }
88 else if (cfg.gerritProject == 'voltha-system-tests') {
89 sh """
90 pushd "$WORKSPACE/${cfg.gerritProject}"
Matteo Scandolo42f6e572021-01-25 15:11:34 -080091 git fetch https://gerrit.opencord.org/${cfg.gerritProject} ${cfg.gerritRefspec} && git checkout FETCH_HEAD
92
93 echo "Currently on commit: \n"
94 git log -1 --oneline
95 popd
96 """
Joey Armstrong775a20f2022-12-02 12:55:43 -050097 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -080098 }
Joey Armstrong775a20f2022-12-02 12:55:43 -050099
100 stage('Clone voltha-helm-charts')
101 {
102 repo_vhc = 'https://gerrit.opencord.org/voltha-helm-charts'
103
104 checkout([
105 $class: 'GitSCM',
106 userRemoteConfigs: [[ url:repo_vhc ]],
107 branches: [[ name: "${cfg.branch}", ]],
108 extensions: [
109 [$class: 'WipeWorkspace'],
110 [$class: 'RelativeTargetDirectory', relativeTargetDir: "voltha-helm-charts"],
111 [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false],
112 ],
113 ])
114
115 if (cfg.volthaHelmChartsChange != '' && cfg.gerritProject != 'voltha-helm-charts') {
116 sh """
117 cd "$WORKSPACE/voltha-helm-charts"
118 git fetch "$repo_vhc" ${cfg.volthaHelmChartsChange} && git checkout FETCH_HEAD
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800119 """
Joey Armstrong775a20f2022-12-02 12:55:43 -0500120 }
121 else if (cfg.gerritProject == 'voltha-helm-charts') {
122 sh """
123 pushd "$WORKSPACE/${cfg.gerritProject}"
124 git fetch "https://gerrit.opencord.org/${cfg.gerritProject}" ${cfg.gerritRefspec} && git checkout FETCH_HEAD
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800125
126 echo "Currently on commit: \n"
127 git log -1 --oneline
128 popd
129 """
Joey Armstrong775a20f2022-12-02 12:55:43 -0500130 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800131 }
Joey Armstrong775a20f2022-12-02 12:55:43 -0500132}
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800133
Joey Armstrong775a20f2022-12-02 12:55:43 -0500134// -----------------------------------------------------------------------
135// -----------------------------------------------------------------------
136def call(Map config)
137{
138 String iam = getIam('main')
139 Boolean debug = false
140
141 if (debug)
142 {
143 println("** ${iam}: ENTER")
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800144 }
Joey Armstrong775a20f2022-12-02 12:55:43 -0500145
146 if (!config) {
147 config = [:]
148 }
149
150 try
151 {
152 wrapped(config)
153 }
154 catch (Exception err)
155 {
156 println("** ${iam}: EXCEPTION ${err}")
157 throw err
158 }
159 finally
160 {
161 if (debug)
162 {
163 println("** ${iam}: LEAVE")
164 }
165 }
166
167 return
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800168}