Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 1 | #!/usr/bin/env groovy |
| 2 | // ----------------------------------------------------------------------- |
Joey Armstrong | def9c40 | 2024-01-30 18:05:29 -0500 | [diff] [blame] | 3 | // Copyright 2021-2024 Open Networking Foundation (ONF) and the ONF Contributors |
Joey Armstrong | af679da | 2023-01-31 14:22:41 -0500 | [diff] [blame] | 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 Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 16 | // ----------------------------------------------------------------------- |
| 17 | |
| 18 | // ----------------------------------------------------------------------- |
| 19 | // ----------------------------------------------------------------------- |
| 20 | def getIam(String func) |
| 21 | { |
| 22 | String src = 'vars/getVolthaCode.groovy' |
| 23 | String iam = [src, func].join('::') |
| 24 | return iam |
| 25 | } |
| 26 | |
Joey Armstrong | def9c40 | 2024-01-30 18:05:29 -0500 | [diff] [blame] | 27 | // ----------------------------------------------------------------------- |
| 28 | // Intent: Log progress message |
| 29 | // ----------------------------------------------------------------------- |
| 30 | void 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 | // ----------------------------------------------------------------------- |
| 40 | void leave(String name) { |
| 41 | // Announce ourselves for log usability |
| 42 | String iam = getIam(name) |
| 43 | println("${iam}: LEAVE") |
| 44 | return |
| 45 | } |
| 46 | |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 47 | // TODO the 3 stages are very similar, most of the code can be shared |
| 48 | |
Joey Armstrong | def9c40 | 2024-01-30 18:05:29 -0500 | [diff] [blame] | 49 | // ----------------------------------------------------------------------- |
| 50 | // ----------------------------------------------------------------------- |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 51 | def wrapped(Map config) |
| 52 | { |
| 53 | def defaultConfig = [ |
Joey Armstrong | def9c40 | 2024-01-30 18:05:29 -0500 | [diff] [blame] | 54 | branch: "master", |
| 55 | gerritProject: "", |
| 56 | gerritRefspec: "", |
| 57 | volthaSystemTestsChange: "", |
| 58 | volthaHelmChartsChange: "", |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 59 | ] |
Joey Armstrong | def9c40 | 2024-01-30 18:05:29 -0500 | [diff] [blame] | 60 | |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 61 | def cfg = defaultConfig + config |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 62 | |
Joey Armstrong | def9c40 | 2024-01-30 18:05:29 -0500 | [diff] [blame] | 63 | println(""" |
| 64 | |
| 65 | ** ----------------------------------------------------------------------- |
| 66 | ** Downloading VOLTHA code with the following parameters: |
| 67 | ** ${cfg} |
| 68 | ** ----------------------------------------------------------------------- |
| 69 | """) |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 70 | |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 71 | stage('Download Patch') |
| 72 | { |
Joey Armstrong | def9c40 | 2024-01-30 18:05:29 -0500 | [diff] [blame] | 73 | frequent_repos = [ |
| 74 | '', |
| 75 | 'voltha-system-tests', |
| 76 | 'voltha-helm-charts', |
| 77 | ] |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 78 | |
Joey Armstrong | def9c40 | 2024-01-30 18:05:29 -0500 | [diff] [blame] | 79 | // 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 Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 94 | |
Joey Armstrong | def9c40 | 2024-01-30 18:05:29 -0500 | [diff] [blame] | 95 | 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 Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 107 | pushd $WORKSPACE/${cfg.gerritProject} |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 108 | 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 Armstrong | def9c40 | 2024-01-30 18:05:29 -0500 | [diff] [blame] | 113 | """) |
| 114 | } |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 115 | } |
| 116 | |
Joey Armstrong | def9c40 | 2024-01-30 18:05:29 -0500 | [diff] [blame] | 117 | // ----------------------------------------------------------------------- |
| 118 | // ----------------------------------------------------------------------- |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 119 | stage('Clone voltha-system-tests') |
Joey Armstrong | def9c40 | 2024-01-30 18:05:29 -0500 | [diff] [blame] | 120 | { |
Joey Armstrong | 93cd494 | 2024-01-30 18:45:46 -0500 | [diff] [blame] | 121 | enter("Clone voltha-system-tests @ BRANCH=[${cfg.branch}]") |
Joey Armstrong | def9c40 | 2024-01-30 18:05:29 -0500 | [diff] [blame] | 122 | println(""" |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 123 | |
Joey Armstrong | def9c40 | 2024-01-30 18:05:29 -0500 | [diff] [blame] | 124 | ** ----------------------------------------------------------------------- |
| 125 | ** Clone voltha-system-tests |
| 126 | ** ----------------------------------------------------------------------- |
| 127 | """) |
| 128 | repo_vst = 'https://gerrit.opencord.org/voltha-system-tests' |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 129 | |
Joey Armstrong | def9c40 | 2024-01-30 18:05:29 -0500 | [diff] [blame] | 130 | 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 Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 146 | cd "$WORKSPACE/voltha-system-tests" |
| 147 | git fetch "${repo_vst}" ${cfg.volthaSystemTestsChange} && git checkout FETCH_HEAD |
| 148 | """ |
Joey Armstrong | def9c40 | 2024-01-30 18:05:29 -0500 | [diff] [blame] | 149 | 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 Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 155 | pushd "$WORKSPACE/${cfg.gerritProject}" |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 156 | 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 Armstrong | def9c40 | 2024-01-30 18:05:29 -0500 | [diff] [blame] | 161 | """) |
| 162 | leave("git fetch https://${cfg.gerritProject}") |
| 163 | } |
| 164 | |
Joey Armstrong | 93cd494 | 2024-01-30 18:45:46 -0500 | [diff] [blame] | 165 | leave("Clone voltha-system-tests @ BRANCH=[${cfg.branch}]") |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 166 | } |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 167 | |
Joey Armstrong | def9c40 | 2024-01-30 18:05:29 -0500 | [diff] [blame] | 168 | // ----------------------------------------------------------------------- |
| 169 | // ----------------------------------------------------------------------- |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 170 | stage('Clone voltha-helm-charts') |
| 171 | { |
Joey Armstrong | 93cd494 | 2024-01-30 18:45:46 -0500 | [diff] [blame] | 172 | enter("Clone voltha-helm-charts @ BRANCH=[${cfg.branch}]") |
Joey Armstrong | def9c40 | 2024-01-30 18:05:29 -0500 | [diff] [blame] | 173 | repo_vhc = 'https://gerrit.opencord.org/voltha-helm-charts' |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 174 | |
Joey Armstrong | def9c40 | 2024-01-30 18:05:29 -0500 | [diff] [blame] | 175 | 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 Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 185 | |
Joey Armstrong | def9c40 | 2024-01-30 18:05:29 -0500 | [diff] [blame] | 186 | if (cfg.volthaHelmChartsChange != '' && cfg.gerritProject != 'voltha-helm-charts') { |
| 187 | enter("git fetch repo_vhc=[$repo_vhc]") |
| 188 | sh """ |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 189 | cd "$WORKSPACE/voltha-helm-charts" |
| 190 | git fetch "$repo_vhc" ${cfg.volthaHelmChartsChange} && git checkout FETCH_HEAD |
Joey Armstrong | daa1f0a | 2024-04-03 18:07:59 -0400 | [diff] [blame] | 191 | """ |
Joey Armstrong | def9c40 | 2024-01-30 18:05:29 -0500 | [diff] [blame] | 192 | 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 Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 197 | pushd "$WORKSPACE/${cfg.gerritProject}" |
| 198 | git fetch "https://gerrit.opencord.org/${cfg.gerritProject}" ${cfg.gerritRefspec} && git checkout FETCH_HEAD |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 199 | |
| 200 | echo "Currently on commit: \n" |
| 201 | git log -1 --oneline |
| 202 | popd |
| 203 | """ |
Joey Armstrong | def9c40 | 2024-01-30 18:05:29 -0500 | [diff] [blame] | 204 | leave('cfg.gerritProject == voltha-helm-charts') |
| 205 | } |
| 206 | |
Joey Armstrong | 93cd494 | 2024-01-30 18:45:46 -0500 | [diff] [blame] | 207 | leave("Clone voltha-helm-charts @ BRANCH=[${cfg.branch}]") |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 208 | } |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 209 | } |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 210 | |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 211 | // ----------------------------------------------------------------------- |
| 212 | // ----------------------------------------------------------------------- |
| 213 | def call(Map config) |
| 214 | { |
| 215 | String iam = getIam('main') |
Joey Armstrong | def9c40 | 2024-01-30 18:05:29 -0500 | [diff] [blame] | 216 | Boolean debug = true |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 217 | |
Joey Armstrong | def9c40 | 2024-01-30 18:05:29 -0500 | [diff] [blame] | 218 | if (debug) { |
| 219 | println("** ${iam}: ENTER") |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 220 | } |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 221 | |
Joey Armstrong | def9c40 | 2024-01-30 18:05:29 -0500 | [diff] [blame] | 222 | config ?: [:] |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 223 | |
| 224 | try |
| 225 | { |
Joey Armstrong | def9c40 | 2024-01-30 18:05:29 -0500 | [diff] [blame] | 226 | wrapped(config) |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 227 | } |
| 228 | catch (Exception err) |
| 229 | { |
Joey Armstrong | def9c40 | 2024-01-30 18:05:29 -0500 | [diff] [blame] | 230 | println("** ${iam}: EXCEPTION ${err}") |
| 231 | throw err |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 232 | } |
| 233 | finally |
| 234 | { |
Joey Armstrong | def9c40 | 2024-01-30 18:05:29 -0500 | [diff] [blame] | 235 | if (debug) |
| 236 | { |
| 237 | println("** ${iam}: LEAVE") |
| 238 | } |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | return |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 242 | } |
Joey Armstrong | af679da | 2023-01-31 14:22:41 -0500 | [diff] [blame] | 243 | |
| 244 | // [EOF] |