blob: 815e719accb3ba2a450f016ac360b7132ba1e195 [file] [log] [blame]
Matteo Scandolo42f6e572021-01-25 15:11:34 -08001// TODO the 3 stages are very similar, most of the code can be shared
2
3def call(Map config) {
4
5 def defaultConfig = [
6 branch: "master",
7 gerritProject: "",
8 gerritRefspec: "",
9 volthaSystemTestsChange: "",
10 volthaHelmChartsChange: "",
11 ]
12
13 if (!config) {
14 config = [:]
15 }
16
17 def cfg = defaultConfig + config
18
19 println "Downloading VOLTHA code with the following parameters: ${cfg}."
20
21 stage('Download Patch') {
22 // We are always downloading those repos, if the patch under test is in one of those
23 // just checkout the patch, no need to clone it again
24 if (cfg.gerritProject != 'voltha-system-tests' &&
25 cfg.gerritProject != 'voltha-helm-charts' &&
26 cfg.gerritProject != '') {
27 checkout([
28 $class: 'GitSCM',
29 userRemoteConfigs: [[
30 url: "https://gerrit.opencord.org/${cfg.gerritProject}",
31 ]],
32 branches: [[ name: "${cfg.branch}", ]],
33 extensions: [
34 [$class: 'WipeWorkspace'],
35 [$class: 'RelativeTargetDirectory', relativeTargetDir: "${cfg.gerritProject}"],
36 [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false],
37 ],
38 ])
39 sh """
40 pushd $WORKSPACE/${cfg.gerritProject}
41 git fetch https://gerrit.opencord.org/${cfg.gerritProject} ${cfg.gerritRefspec} && git checkout FETCH_HEAD
42
43 echo "Currently on commit: \n"
44 git log -1 --oneline
45 popd
46 """
47 }
48 }
49 stage('Clone voltha-system-tests') {
50 checkout([
51 $class: 'GitSCM',
52 userRemoteConfigs: [[
53 url: "https://gerrit.opencord.org/voltha-system-tests",
54 ]],
55 branches: [[ name: "${cfg.branch}", ]],
56 extensions: [
57 [$class: 'WipeWorkspace'],
58 [$class: 'RelativeTargetDirectory', relativeTargetDir: "voltha-system-tests"],
59 [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false],
60 ],
61 ])
62 if (cfg.volthaSystemTestsChange != '' && cfg.gerritProject != 'voltha-system-tests') {
63 sh """
64 cd $WORKSPACE/voltha-system-tests
65 git fetch https://gerrit.opencord.org/voltha-system-tests ${cfg.volthaSystemTestsChange} && git checkout FETCH_HEAD
66 """
67 }
68 else if (cfg.gerritProject == 'voltha-system-tests') {
69 sh """
70 pushd $WORKSPACE/${cfg.gerritProject}
71 git fetch https://gerrit.opencord.org/${cfg.gerritProject} ${cfg.gerritRefspec} && git checkout FETCH_HEAD
72
73 echo "Currently on commit: \n"
74 git log -1 --oneline
75 popd
76 """
77 }
78 }
79 stage('Clone voltha-helm-charts') {
80 checkout([
81 $class: 'GitSCM',
82 userRemoteConfigs: [[
83 url: "https://gerrit.opencord.org/voltha-helm-charts",
84 ]],
85 branches: [[ name: "master", ]],
86 extensions: [
87 [$class: 'WipeWorkspace'],
88 [$class: 'RelativeTargetDirectory', relativeTargetDir: "voltha-helm-charts"],
89 [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false],
90 ],
91 ])
92 if (cfg.volthaHelmChartsChange != '' && cfg.gerritProject != 'voltha-helm-charts') {
93 sh """
94 cd $WORKSPACE/voltha-helm-charts
95 git fetch https://gerrit.opencord.org/voltha-helm-charts ${cfg.volthaHelmChartsChange} && git checkout FETCH_HEAD
96 """
97 }
98 else if (cfg.gerritProject == 'voltha-helm-charts') {
99 sh """
100 pushd $WORKSPACE/${cfg.gerritProject}
101 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 """
107 }
108 }
109}