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 |
| 40 | if ( !(cfg.gerritProject in frequent_repos)) |
| 41 | { |
| 42 | repo_project = "https://gerrit.opencord.org/${cfg.gerritProject}" |
| 43 | |
| 44 | checkout([ |
| 45 | $class: 'GitSCM', |
| 46 | userRemoteConfigs: [[ url:repo_project ]], |
| 47 | branches: [[ name: "${cfg.branch}", ]], |
| 48 | extensions: [ |
| 49 | [$class: 'WipeWorkspace'], |
| 50 | [$class: 'RelativeTargetDirectory', relativeTargetDir: "${cfg.gerritProject}"], |
| 51 | [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false], |
| 52 | ], |
| 53 | ]) |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 54 | |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame^] | 55 | sh """ |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 56 | pushd $WORKSPACE/${cfg.gerritProject} |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame^] | 57 | git fetch "$repo_project" ${cfg.gerritRefspec} && git checkout FETCH_HEAD |
| 58 | |
| 59 | echo "Currently on commit: \n" |
| 60 | git log -1 --oneline |
| 61 | popd |
| 62 | """ |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | stage('Clone voltha-system-tests') |
| 67 | { |
| 68 | repo_vst = 'https://gerrit.opencord.org/voltha-system-tests' |
| 69 | |
| 70 | checkout([ |
| 71 | $class: 'GitSCM', |
| 72 | userRemoteConfigs: [[ url:repo_url ]], |
| 73 | branches: [[ name: "${cfg.branch}", ]], |
| 74 | extensions: [ |
| 75 | [$class: 'WipeWorkspace'], |
| 76 | [$class: 'RelativeTargetDirectory', relativeTargetDir: "voltha-system-tests"], |
| 77 | [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false], |
| 78 | ], |
| 79 | ]) |
| 80 | |
| 81 | if (cfg.volthaSystemTestsChange != '' && cfg.gerritProject != 'voltha-system-tests') |
| 82 | { |
| 83 | sh """ |
| 84 | cd "$WORKSPACE/voltha-system-tests" |
| 85 | git fetch "${repo_vst}" ${cfg.volthaSystemTestsChange} && git checkout FETCH_HEAD |
| 86 | """ |
| 87 | } |
| 88 | else if (cfg.gerritProject == 'voltha-system-tests') { |
| 89 | sh """ |
| 90 | pushd "$WORKSPACE/${cfg.gerritProject}" |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 91 | git fetch https://gerrit.opencord.org/${cfg.gerritProject} ${cfg.gerritRefspec} && git checkout FETCH_HEAD |
| 92 | |
| 93 | echo "Currently on commit: \n" |
| 94 | git log -1 --oneline |
| 95 | popd |
| 96 | """ |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame^] | 97 | } |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 98 | } |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame^] | 99 | |
| 100 | stage('Clone voltha-helm-charts') |
| 101 | { |
| 102 | repo_vhc = 'https://gerrit.opencord.org/voltha-helm-charts' |
| 103 | |
| 104 | checkout([ |
| 105 | $class: 'GitSCM', |
| 106 | userRemoteConfigs: [[ url:repo_vhc ]], |
| 107 | branches: [[ name: "${cfg.branch}", ]], |
| 108 | extensions: [ |
| 109 | [$class: 'WipeWorkspace'], |
| 110 | [$class: 'RelativeTargetDirectory', relativeTargetDir: "voltha-helm-charts"], |
| 111 | [$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false], |
| 112 | ], |
| 113 | ]) |
| 114 | |
| 115 | if (cfg.volthaHelmChartsChange != '' && cfg.gerritProject != 'voltha-helm-charts') { |
| 116 | sh """ |
| 117 | cd "$WORKSPACE/voltha-helm-charts" |
| 118 | git fetch "$repo_vhc" ${cfg.volthaHelmChartsChange} && git checkout FETCH_HEAD |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 119 | """ |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame^] | 120 | } |
| 121 | else if (cfg.gerritProject == 'voltha-helm-charts') { |
| 122 | sh """ |
| 123 | pushd "$WORKSPACE/${cfg.gerritProject}" |
| 124 | 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] | 125 | |
| 126 | echo "Currently on commit: \n" |
| 127 | git log -1 --oneline |
| 128 | popd |
| 129 | """ |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame^] | 130 | } |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 131 | } |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame^] | 132 | } |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 133 | |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame^] | 134 | // ----------------------------------------------------------------------- |
| 135 | // ----------------------------------------------------------------------- |
| 136 | def call(Map config) |
| 137 | { |
| 138 | String iam = getIam('main') |
| 139 | Boolean debug = false |
| 140 | |
| 141 | if (debug) |
| 142 | { |
| 143 | println("** ${iam}: ENTER") |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 144 | } |
Joey Armstrong | 775a20f | 2022-12-02 12:55:43 -0500 | [diff] [blame^] | 145 | |
| 146 | if (!config) { |
| 147 | config = [:] |
| 148 | } |
| 149 | |
| 150 | try |
| 151 | { |
| 152 | wrapped(config) |
| 153 | } |
| 154 | catch (Exception err) |
| 155 | { |
| 156 | println("** ${iam}: EXCEPTION ${err}") |
| 157 | throw err |
| 158 | } |
| 159 | finally |
| 160 | { |
| 161 | if (debug) |
| 162 | { |
| 163 | println("** ${iam}: LEAVE") |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | return |
Matteo Scandolo | 42f6e57 | 2021-01-25 15:11:34 -0800 | [diff] [blame] | 168 | } |