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 | |
Eric Ball | 3f0cec3 | 2024-10-10 17:16:03 -0700 | [diff] [blame] | 79 | // We are always downloading those repos, if the patch under test is in |
| 80 | // one of those just checkout the patch, no need to clone it again |
Joey Armstrong | def9c40 | 2024-01-30 18:05:29 -0500 | [diff] [blame] | 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 | } |
Eric Ball | 3f0cec3 | 2024-10-10 17:16:03 -0700 | [diff] [blame] | 91 | else if (params.GERRIT_PROJECT == "onf-make") |
| 92 | { |
| 93 | // When testing onf-make, the tests are kicked off from the onf-make |
| 94 | // repo, so the GERRIT_PROJECT and GERRIT_PATCHSET_REVISION params |
| 95 | // will carry the data of what we want the submodule to be. |
| 96 | // However, the gerritProject is overridden, so that we can pull |
| 97 | // in another repo and run the tests to make sure that they work |
| 98 | // with the code changes to onf-make. |
| 99 | repo_project = "https://gerrit.opencord.org/${cfg.gerritProject}" |
| 100 | |
| 101 | checkout([ |
| 102 | $class: 'GitSCM', |
| 103 | userRemoteConfigs: [[ url:repo_project ]], |
| 104 | branches: [[ name: "${cfg.branch}", ]], |
| 105 | extensions: [ |
| 106 | [$class: 'WipeWorkspace'], |
| 107 | [$class: 'RelativeTargetDirectory', relativeTargetDir: "${cfg.gerritProject}"], |
| 108 | [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false], |
| 109 | submodule(recursiveSubmodules: true, reference: "${params.GERRIT_PATCHSET_REVISION}"), |
| 110 | ], |
| 111 | ]) |
| 112 | |
| 113 | sh("""pushd $WORKSPACE/${cfg.gerritProject} |
| 114 | git fetch "$repo_project" ${cfg.gerritRefspec} && git checkout FETCH_HEAD |
| 115 | |
| 116 | echo "Currently on commit: \n" |
| 117 | git log -1 --oneline |
| 118 | popd |
| 119 | """) |
| 120 | } |
Joey Armstrong | def9c40 | 2024-01-30 18:05:29 -0500 | [diff] [blame] | 121 | else if (!(cfg.gerritProject in frequent_repos)) |
| 122 | { |
| 123 | repo_project = "https://gerrit.opencord.org/${cfg.gerritProject}" |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 124 | |
Joey Armstrong | def9c40 | 2024-01-30 18:05:29 -0500 | [diff] [blame] | 125 | checkout([ |
| 126 | $class: 'GitSCM', |
| 127 | userRemoteConfigs: [[ url:repo_project ]], |
| 128 | branches: [[ name: "${cfg.branch}", ]], |
| 129 | extensions: [ |
| 130 | [$class: 'WipeWorkspace'], |
| 131 | [$class: 'RelativeTargetDirectory', relativeTargetDir: "${cfg.gerritProject}"], |
| 132 | [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false], |
| 133 | ], |
| 134 | ]) |
| 135 | |
Eric Ball | 3f0cec3 | 2024-10-10 17:16:03 -0700 | [diff] [blame] | 136 | sh("""pushd $WORKSPACE/${cfg.gerritProject} |
| 137 | git fetch "$repo_project" ${cfg.gerritRefspec} && git checkout FETCH_HEAD |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 138 | |
Eric Ball | 3f0cec3 | 2024-10-10 17:16:03 -0700 | [diff] [blame] | 139 | echo "Currently on commit: \n" |
| 140 | git log -1 --oneline |
| 141 | popd |
| 142 | """) |
Joey Armstrong | def9c40 | 2024-01-30 18:05:29 -0500 | [diff] [blame] | 143 | } |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 144 | } |
| 145 | |
Joey Armstrong | def9c40 | 2024-01-30 18:05:29 -0500 | [diff] [blame] | 146 | // ----------------------------------------------------------------------- |
| 147 | // ----------------------------------------------------------------------- |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 148 | stage('Clone voltha-system-tests') |
Joey Armstrong | def9c40 | 2024-01-30 18:05:29 -0500 | [diff] [blame] | 149 | { |
Joey Armstrong | 93cd494 | 2024-01-30 18:45:46 -0500 | [diff] [blame] | 150 | enter("Clone voltha-system-tests @ BRANCH=[${cfg.branch}]") |
Joey Armstrong | def9c40 | 2024-01-30 18:05:29 -0500 | [diff] [blame] | 151 | println(""" |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 152 | |
Joey Armstrong | def9c40 | 2024-01-30 18:05:29 -0500 | [diff] [blame] | 153 | ** ----------------------------------------------------------------------- |
| 154 | ** Clone voltha-system-tests |
| 155 | ** ----------------------------------------------------------------------- |
| 156 | """) |
| 157 | repo_vst = 'https://gerrit.opencord.org/voltha-system-tests' |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 158 | |
Joey Armstrong | def9c40 | 2024-01-30 18:05:29 -0500 | [diff] [blame] | 159 | checkout([ |
| 160 | $class: 'GitSCM', |
| 161 | userRemoteConfigs: [[ url:repo_vst ]], |
| 162 | branches: [[ name: "${cfg.branch}", ]], |
| 163 | extensions: [ |
| 164 | [$class: 'WipeWorkspace'], |
| 165 | [$class: 'RelativeTargetDirectory', relativeTargetDir: "voltha-system-tests"], |
| 166 | [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false], |
| 167 | ], |
| 168 | ]) |
| 169 | |
| 170 | if (cfg.volthaSystemTestsChange != '' && cfg.gerritProject != 'voltha-system-tests') |
| 171 | { |
| 172 | enter("git fetch repo_vst=[${repo_vst}]") |
| 173 | |
| 174 | sh """ |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 175 | cd "$WORKSPACE/voltha-system-tests" |
| 176 | git fetch "${repo_vst}" ${cfg.volthaSystemTestsChange} && git checkout FETCH_HEAD |
| 177 | """ |
Joey Armstrong | def9c40 | 2024-01-30 18:05:29 -0500 | [diff] [blame] | 178 | leave("git fetch repo_vst=[${repo_vst}]") |
| 179 | } |
| 180 | else if (cfg.gerritProject == 'voltha-system-tests') { |
| 181 | enter("git fetch https://${cfg.gerritProject}") |
| 182 | |
| 183 | sh(""" |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 184 | pushd "$WORKSPACE/${cfg.gerritProject}" |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 185 | git fetch https://gerrit.opencord.org/${cfg.gerritProject} ${cfg.gerritRefspec} && git checkout FETCH_HEAD |
| 186 | |
| 187 | echo "Currently on commit: \n" |
| 188 | git log -1 --oneline |
| 189 | popd |
Joey Armstrong | def9c40 | 2024-01-30 18:05:29 -0500 | [diff] [blame] | 190 | """) |
| 191 | leave("git fetch https://${cfg.gerritProject}") |
| 192 | } |
| 193 | |
Joey Armstrong | 93cd494 | 2024-01-30 18:45:46 -0500 | [diff] [blame] | 194 | leave("Clone voltha-system-tests @ BRANCH=[${cfg.branch}]") |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 195 | } |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 196 | |
Joey Armstrong | def9c40 | 2024-01-30 18:05:29 -0500 | [diff] [blame] | 197 | // ----------------------------------------------------------------------- |
| 198 | // ----------------------------------------------------------------------- |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 199 | stage('Clone voltha-helm-charts') |
| 200 | { |
Joey Armstrong | 93cd494 | 2024-01-30 18:45:46 -0500 | [diff] [blame] | 201 | enter("Clone voltha-helm-charts @ BRANCH=[${cfg.branch}]") |
Joey Armstrong | def9c40 | 2024-01-30 18:05:29 -0500 | [diff] [blame] | 202 | repo_vhc = 'https://gerrit.opencord.org/voltha-helm-charts' |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 203 | |
Joey Armstrong | def9c40 | 2024-01-30 18:05:29 -0500 | [diff] [blame] | 204 | checkout([ |
| 205 | $class: 'GitSCM', |
| 206 | userRemoteConfigs: [[ url:repo_vhc ]], |
| 207 | branches: [[ name: "${cfg.branch}", ]], |
| 208 | extensions: [ |
| 209 | [$class: 'WipeWorkspace'], |
| 210 | [$class: 'RelativeTargetDirectory', relativeTargetDir: "voltha-helm-charts"], |
| 211 | [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false], |
| 212 | ], |
| 213 | ]) |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 214 | |
Joey Armstrong | def9c40 | 2024-01-30 18:05:29 -0500 | [diff] [blame] | 215 | if (cfg.volthaHelmChartsChange != '' && cfg.gerritProject != 'voltha-helm-charts') { |
| 216 | enter("git fetch repo_vhc=[$repo_vhc]") |
| 217 | sh """ |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 218 | cd "$WORKSPACE/voltha-helm-charts" |
| 219 | git fetch "$repo_vhc" ${cfg.volthaHelmChartsChange} && git checkout FETCH_HEAD |
Joey Armstrong | daa1f0a | 2024-04-03 18:07:59 -0400 | [diff] [blame] | 220 | """ |
Joey Armstrong | def9c40 | 2024-01-30 18:05:29 -0500 | [diff] [blame] | 221 | leave("git fetch repo_vhc=[$repo_vhc]") |
| 222 | } |
| 223 | else if (cfg.gerritProject == 'voltha-helm-charts') { |
| 224 | enter('cfg.gerritProject == voltha-helm-charts') |
| 225 | sh """ |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 226 | pushd "$WORKSPACE/${cfg.gerritProject}" |
| 227 | 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] | 228 | |
| 229 | echo "Currently on commit: \n" |
| 230 | git log -1 --oneline |
| 231 | popd |
| 232 | """ |
Joey Armstrong | def9c40 | 2024-01-30 18:05:29 -0500 | [diff] [blame] | 233 | leave('cfg.gerritProject == voltha-helm-charts') |
| 234 | } |
| 235 | |
Joey Armstrong | 93cd494 | 2024-01-30 18:45:46 -0500 | [diff] [blame] | 236 | leave("Clone voltha-helm-charts @ BRANCH=[${cfg.branch}]") |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 237 | } |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 238 | } |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 239 | |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 240 | // ----------------------------------------------------------------------- |
| 241 | // ----------------------------------------------------------------------- |
| 242 | def call(Map config) |
| 243 | { |
| 244 | String iam = getIam('main') |
Joey Armstrong | def9c40 | 2024-01-30 18:05:29 -0500 | [diff] [blame] | 245 | Boolean debug = true |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 246 | |
Joey Armstrong | def9c40 | 2024-01-30 18:05:29 -0500 | [diff] [blame] | 247 | if (debug) { |
| 248 | println("** ${iam}: ENTER") |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 249 | } |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 250 | |
Joey Armstrong | def9c40 | 2024-01-30 18:05:29 -0500 | [diff] [blame] | 251 | config ?: [:] |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 252 | |
| 253 | try |
| 254 | { |
Joey Armstrong | def9c40 | 2024-01-30 18:05:29 -0500 | [diff] [blame] | 255 | wrapped(config) |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 256 | } |
| 257 | catch (Exception err) |
| 258 | { |
Joey Armstrong | def9c40 | 2024-01-30 18:05:29 -0500 | [diff] [blame] | 259 | println("** ${iam}: EXCEPTION ${err}") |
| 260 | throw err |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 261 | } |
| 262 | finally |
| 263 | { |
Joey Armstrong | def9c40 | 2024-01-30 18:05:29 -0500 | [diff] [blame] | 264 | if (debug) |
| 265 | { |
| 266 | println("** ${iam}: LEAVE") |
| 267 | } |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | return |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 271 | } |
Joey Armstrong | af679da | 2023-01-31 14:22:41 -0500 | [diff] [blame] | 272 | |
| 273 | // [EOF] |