Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 1 | #!/usr/bin/env groovy |
| 2 | // ----------------------------------------------------------------------- |
Joey Armstrong | af679da | 2023-01-31 14:22:41 -0500 | [diff] [blame] | 3 | // Copyright 2021-2023 Open Networking Foundation (ONF) and the ONF Contributors |
| 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 | |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 27 | // TODO the 3 stages are very similar, most of the code can be shared |
| 28 | |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 29 | def wrapped(Map config) |
| 30 | { |
| 31 | def defaultConfig = [ |
| 32 | branch: "master", |
| 33 | gerritProject: "", |
| 34 | gerritRefspec: "", |
| 35 | volthaSystemTestsChange: "", |
| 36 | volthaHelmChartsChange: "", |
| 37 | ] |
| 38 | |
| 39 | def cfg = defaultConfig + config |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 40 | |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 41 | println "Downloading VOLTHA code with the following parameters: ${cfg}." |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 42 | |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 43 | stage('Download Patch') |
| 44 | { |
| 45 | frequent_repos = [ |
| 46 | '', |
| 47 | 'voltha-system-tests', |
| 48 | 'voltha-helm-charts', |
| 49 | ] |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 50 | |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 51 | // We are always downloading those repos, if the patch under test is in one of those |
| 52 | // just checkout the patch, no need to clone it again |
Joey Armstrong | acb4442 | 2022-12-21 06:15:59 -0500 | [diff] [blame] | 53 | if (cfg.gerritProject == '') |
| 54 | { |
| 55 | // Revisit: |
| 56 | // gerritProject should be defined. Ignore when empty was likely |
| 57 | // added to support manually re-running a job when repo values |
| 58 | // may not be defined. |
| 59 | // Unfortunately the conditional can also inadvertently bypass |
| 60 | // checkout during an error condition. |
| 61 | // Case: when cfg= is invalid due to a jenkins hiccup. |
| 62 | } |
Joey Armstrong | d0fd3d6 | 2022-12-21 15:47:39 -0500 | [diff] [blame] | 63 | else if (!(cfg.gerritProject in frequent_repos)) |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 64 | { |
| 65 | repo_project = "https://gerrit.opencord.org/${cfg.gerritProject}" |
| 66 | |
| 67 | checkout([ |
| 68 | $class: 'GitSCM', |
| 69 | userRemoteConfigs: [[ url:repo_project ]], |
| 70 | branches: [[ name: "${cfg.branch}", ]], |
| 71 | extensions: [ |
| 72 | [$class: 'WipeWorkspace'], |
| 73 | [$class: 'RelativeTargetDirectory', relativeTargetDir: "${cfg.gerritProject}"], |
| 74 | [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false], |
| 75 | ], |
| 76 | ]) |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 77 | |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 78 | sh """ |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 79 | pushd $WORKSPACE/${cfg.gerritProject} |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 80 | git fetch "$repo_project" ${cfg.gerritRefspec} && git checkout FETCH_HEAD |
| 81 | |
| 82 | echo "Currently on commit: \n" |
| 83 | git log -1 --oneline |
| 84 | popd |
| 85 | """ |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | stage('Clone voltha-system-tests') |
| 90 | { |
| 91 | repo_vst = 'https://gerrit.opencord.org/voltha-system-tests' |
| 92 | |
| 93 | checkout([ |
| 94 | $class: 'GitSCM', |
Joey Armstrong | ea6aaa9 | 2022-12-19 19:00:46 -0500 | [diff] [blame] | 95 | userRemoteConfigs: [[ url:repo_vst ]], |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 96 | branches: [[ name: "${cfg.branch}", ]], |
| 97 | extensions: [ |
| 98 | [$class: 'WipeWorkspace'], |
| 99 | [$class: 'RelativeTargetDirectory', relativeTargetDir: "voltha-system-tests"], |
| 100 | [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false], |
| 101 | ], |
| 102 | ]) |
| 103 | |
| 104 | if (cfg.volthaSystemTestsChange != '' && cfg.gerritProject != 'voltha-system-tests') |
| 105 | { |
| 106 | sh """ |
| 107 | cd "$WORKSPACE/voltha-system-tests" |
| 108 | git fetch "${repo_vst}" ${cfg.volthaSystemTestsChange} && git checkout FETCH_HEAD |
| 109 | """ |
| 110 | } |
| 111 | else if (cfg.gerritProject == 'voltha-system-tests') { |
| 112 | sh """ |
| 113 | pushd "$WORKSPACE/${cfg.gerritProject}" |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 114 | git fetch https://gerrit.opencord.org/${cfg.gerritProject} ${cfg.gerritRefspec} && git checkout FETCH_HEAD |
| 115 | |
| 116 | echo "Currently on commit: \n" |
| 117 | git log -1 --oneline |
| 118 | popd |
| 119 | """ |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 120 | } |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 121 | } |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 122 | |
| 123 | stage('Clone voltha-helm-charts') |
| 124 | { |
| 125 | repo_vhc = 'https://gerrit.opencord.org/voltha-helm-charts' |
| 126 | |
| 127 | checkout([ |
| 128 | $class: 'GitSCM', |
| 129 | userRemoteConfigs: [[ url:repo_vhc ]], |
| 130 | branches: [[ name: "${cfg.branch}", ]], |
| 131 | extensions: [ |
| 132 | [$class: 'WipeWorkspace'], |
| 133 | [$class: 'RelativeTargetDirectory', relativeTargetDir: "voltha-helm-charts"], |
| 134 | [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false], |
| 135 | ], |
| 136 | ]) |
| 137 | |
| 138 | if (cfg.volthaHelmChartsChange != '' && cfg.gerritProject != 'voltha-helm-charts') { |
| 139 | sh """ |
| 140 | cd "$WORKSPACE/voltha-helm-charts" |
| 141 | git fetch "$repo_vhc" ${cfg.volthaHelmChartsChange} && git checkout FETCH_HEAD |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 142 | """ |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 143 | } |
| 144 | else if (cfg.gerritProject == 'voltha-helm-charts') { |
| 145 | sh """ |
| 146 | pushd "$WORKSPACE/${cfg.gerritProject}" |
| 147 | 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] | 148 | |
| 149 | echo "Currently on commit: \n" |
| 150 | git log -1 --oneline |
| 151 | popd |
| 152 | """ |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 153 | } |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 154 | } |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 155 | } |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 156 | |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 157 | // ----------------------------------------------------------------------- |
| 158 | // ----------------------------------------------------------------------- |
| 159 | def call(Map config) |
| 160 | { |
| 161 | String iam = getIam('main') |
| 162 | Boolean debug = false |
| 163 | |
| 164 | if (debug) |
| 165 | { |
| 166 | println("** ${iam}: ENTER") |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 167 | } |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame] | 168 | |
| 169 | if (!config) { |
| 170 | config = [:] |
| 171 | } |
| 172 | |
| 173 | try |
| 174 | { |
| 175 | wrapped(config) |
| 176 | } |
| 177 | catch (Exception err) |
| 178 | { |
| 179 | println("** ${iam}: EXCEPTION ${err}") |
| 180 | throw err |
| 181 | } |
| 182 | finally |
| 183 | { |
| 184 | if (debug) |
| 185 | { |
| 186 | println("** ${iam}: LEAVE") |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | return |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 191 | } |
Joey Armstrong | af679da | 2023-01-31 14:22:41 -0500 | [diff] [blame] | 192 | |
| 193 | // [EOF] |