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