You Wang | 5c15a7a | 2020-04-02 11:24:33 -0700 | [diff] [blame] | 1 | // Copyright 2020-present Open Networking Foundation |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | // omec-postmerge.groovy |
You Wang | 4023945 | 2020-06-11 20:17:15 -0700 | [diff] [blame] | 16 | // Combines docker-publish, deploy and test pipelines into one job that can be triggered by a GitHub PR merge |
You Wang | 5c15a7a | 2020-04-02 11:24:33 -0700 | [diff] [blame] | 17 | |
You Wang | 5c15a7a | 2020-04-02 11:24:33 -0700 | [diff] [blame] | 18 | |
| 19 | pipeline { |
| 20 | |
| 21 | agent { |
| 22 | label "${params.buildNode}" |
| 23 | } |
| 24 | |
You Wang | 4023945 | 2020-06-11 20:17:15 -0700 | [diff] [blame] | 25 | stages { |
| 26 | stage('Build and Publish') { |
You Wang | 5c15a7a | 2020-04-02 11:24:33 -0700 | [diff] [blame] | 27 | steps { |
Jeremy Ronquillo | d91e308 | 2020-04-09 11:32:41 -0700 | [diff] [blame] | 28 | script { |
You Wang | 425d49f | 2020-07-29 21:43:28 -0700 | [diff] [blame] | 29 | build_job_name = "docker-publish-github_$repoName" |
| 30 | if ("${repoName}" == "spgw"){ |
| 31 | build_job_name = "aether-member-only-jobs/" + build_job_name |
| 32 | } |
Jeremy Ronquillo | d91e308 | 2020-04-09 11:32:41 -0700 | [diff] [blame] | 33 | abbreviated_commit_hash = commitHash.substring(0, 7) |
Jeremy Ronquillo | 6e42f8c | 2020-04-27 14:13:51 -0700 | [diff] [blame] | 34 | tags_to_build = [ "${branchName}-latest", |
You Wang | 7673e48 | 2020-09-18 16:33:34 -0700 | [diff] [blame] | 35 | "${branchName}-${abbreviated_commit_hash}" ] |
| 36 | env_vars = [ "", "" ] |
| 37 | if ("${repoName}" == "upf-epc"){ |
| 38 | tags_to_build += [ "${branchName}-latest-ivybridge", |
| 39 | "${branchName}-${abbreviated_commit_hash}-ivybridge" ] |
| 40 | env_vars = [ "CPU=haswell", "CPU=haswell", "CPU=ivybridge", "CPU=ivybridge" ] |
Jeremy Ronquillo | 6e42f8c | 2020-04-27 14:13:51 -0700 | [diff] [blame] | 41 | } |
You Wang | 7673e48 | 2020-09-18 16:33:34 -0700 | [diff] [blame] | 42 | def builds = [:] |
| 43 | for(i = 0; i < tags_to_build.size(); i += 1) { |
| 44 | def tag_to_build = tags_to_build[i] |
| 45 | def env_var = env_vars[i] |
| 46 | builds["${build_job_name}${i}"] = { |
| 47 | build job: "${build_job_name}", parameters: [ |
| 48 | string(name: 'gitUrl', value: "${repoUrl}"), |
| 49 | string(name: 'gitRef', value: "${branchName}"), |
| 50 | string(name: 'branchName', value: tag_to_build), |
| 51 | string(name: 'projectName', value: "${repoName}"), |
| 52 | string(name: 'extraEnvironmentVars', value: env_var), |
| 53 | ] |
| 54 | } |
| 55 | } |
| 56 | parallel builds |
Jeremy Ronquillo | d91e308 | 2020-04-09 11:32:41 -0700 | [diff] [blame] | 57 | } |
You Wang | 5c15a7a | 2020-04-02 11:24:33 -0700 | [diff] [blame] | 58 | } |
| 59 | } |
| 60 | |
You Wang | ae518b5 | 2020-09-21 16:29:25 -0700 | [diff] [blame] | 61 | stage ("Get Image Tags"){ |
You Wang | 5c15a7a | 2020-04-02 11:24:33 -0700 | [diff] [blame] | 62 | steps { |
| 63 | script { |
You Wang | 7673e48 | 2020-09-18 16:33:34 -0700 | [diff] [blame] | 64 | hssdb_tag = sh returnStdout: true, script: """curl -s 'https://registry.hub.docker.com/v2/repositories/omecproject/c3po-hssdb/tags/' | jq '.results[] | select(.name | test("${c3poBranchName}-[0-9a-z]{7}\$")).name' | head -1 | tr -d \\\"""" |
| 65 | hss_tag = sh returnStdout: true, script: """curl -s 'https://registry.hub.docker.com/v2/repositories/omecproject/c3po-hss/tags/' | jq '.results[] | select(.name | test("${c3poBranchName}-[0-9a-z]{7}\$")).name' | head -1 | tr -d \\\"""" |
| 66 | mme_tag = sh returnStdout: true, script: """curl -s 'https://registry.hub.docker.com/v2/repositories/omecproject/nucleus/tags/' | jq '.results[] | select(.name | test("${nucleusBranchName}-[0-9a-z]{7}\$")).name' | head -1 | tr -d \\\"""" |
| 67 | spgwc_tag = sh returnStdout: true, script: """curl -s 'https://registry.hub.docker.com/v2/repositories/omecproject/spgw/tags/' | jq '.results[] | select(.name | test("${spgwBranchName}-[0-9a-z]{7}\$")).name' | head -1 | tr -d \\\"""" |
| 68 | bess_tag = sh returnStdout: true, script: """curl -s 'https://registry.hub.docker.com/v2/repositories/omecproject/upf-epc-bess/tags/' | jq '.results[] | select(.name | test("${upfBranchName}-[0-9a-z]{7}\$")).name' | head -1 | tr -d \\\"""" |
| 69 | zmqiface_tag = sh returnStdout: true, script: """curl -s 'https://registry.hub.docker.com/v2/repositories/omecproject/upf-epc-cpiface/tags/' | jq '.results[] | select(.name | test("${upfBranchName}-[0-9a-z]{7}\$")).name' | head -1 | tr -d \\\"""" |
| 70 | pfcpiface_tag = sh returnStdout: true, script: """curl -s 'https://registry.hub.docker.com/v2/repositories/omecproject/upf-epc-pfcpiface/tags/' | jq '.results[] | select(.name | test("${upfBranchName}-[0-9a-z]{7}\$")).name' | head -1 | tr -d \\\"""" |
You Wang | 4023945 | 2020-06-11 20:17:15 -0700 | [diff] [blame] | 71 | |
| 72 | hssdb_image = "omecproject/c3po-hssdb:"+hssdb_tag |
| 73 | hss_image = "omecproject/c3po-hss:"+hss_tag |
| 74 | mme_image = "omecproject/nucleus:"+mme_tag |
You Wang | 425d49f | 2020-07-29 21:43:28 -0700 | [diff] [blame] | 75 | spgwc_image = "omecproject/spgw:"+spgwc_tag |
You Wang | e1cbba2 | 2020-06-15 21:16:14 -0700 | [diff] [blame] | 76 | bess_image = "omecproject/upf-epc-bess:"+bess_tag |
You Wang | 425d49f | 2020-07-29 21:43:28 -0700 | [diff] [blame] | 77 | zmqiface_image = "omecproject/upf-epc-cpiface:"+zmqiface_tag |
| 78 | pfcpiface_image = "omecproject/upf-epc-pfcpiface:"+pfcpiface_tag |
You Wang | 4023945 | 2020-06-11 20:17:15 -0700 | [diff] [blame] | 79 | |
You Wang | ae518b5 | 2020-09-21 16:29:25 -0700 | [diff] [blame] | 80 | updatedImages = "" |
You Wang | 5c15a7a | 2020-04-02 11:24:33 -0700 | [diff] [blame] | 81 | switch("${params.repoName}") { |
| 82 | case "c3po": |
You Wang | 4023945 | 2020-06-11 20:17:15 -0700 | [diff] [blame] | 83 | hssdb_image = "${params.registry}/c3po-hssdb:${branchName}-${abbreviated_commit_hash}" |
| 84 | hss_image = "${params.registry}/c3po-hss:${branchName}-${abbreviated_commit_hash}" |
You Wang | ae518b5 | 2020-09-21 16:29:25 -0700 | [diff] [blame] | 85 | updatedImages += hssdb_image + "," |
| 86 | updatedImages += hss_image |
You Wang | 5c15a7a | 2020-04-02 11:24:33 -0700 | [diff] [blame] | 87 | break |
You Wang | 425d49f | 2020-07-29 21:43:28 -0700 | [diff] [blame] | 88 | case "spgw": |
| 89 | spgwc_image = "${params.registry}/spgw:${branchName}-${abbreviated_commit_hash}" |
You Wang | ae518b5 | 2020-09-21 16:29:25 -0700 | [diff] [blame] | 90 | updatedImages += spgwc_image |
You Wang | 5c15a7a | 2020-04-02 11:24:33 -0700 | [diff] [blame] | 91 | break |
You Wang | 4023945 | 2020-06-11 20:17:15 -0700 | [diff] [blame] | 92 | case "Nucleus": |
| 93 | mme_image = "${params.registry}/nucleus:${branchName}-${abbreviated_commit_hash}" |
You Wang | ae518b5 | 2020-09-21 16:29:25 -0700 | [diff] [blame] | 94 | updatedImages += mme_image |
You Wang | 5c15a7a | 2020-04-02 11:24:33 -0700 | [diff] [blame] | 95 | break |
You Wang | e1cbba2 | 2020-06-15 21:16:14 -0700 | [diff] [blame] | 96 | case "upf-epc": |
| 97 | bess_image = "${params.registry}/upf-epc-bess:${branchName}-${abbreviated_commit_hash}" |
You Wang | 425d49f | 2020-07-29 21:43:28 -0700 | [diff] [blame] | 98 | zmqiface_image = "${params.registry}/upf-epc-cpiface:${branchName}-${abbreviated_commit_hash}" |
| 99 | pfcpiface_image = "${params.registry}/upf-epc-pfcpiface:${branchName}-${abbreviated_commit_hash}" |
You Wang | ae518b5 | 2020-09-21 16:29:25 -0700 | [diff] [blame] | 100 | updatedImages += bess_image + "," |
| 101 | updatedImages += zmqiface_image + "," |
| 102 | updatedImages += pfcpiface_image + "," |
| 103 | updatedImages += bess_image + "-ivybridge," |
| 104 | updatedImages += zmqiface_image + "-ivybridge," |
| 105 | updatedImages += pfcpiface_image + "-ivybridge" |
You Wang | e1cbba2 | 2020-06-15 21:16:14 -0700 | [diff] [blame] | 106 | break |
You Wang | 5c15a7a | 2020-04-02 11:24:33 -0700 | [diff] [blame] | 107 | } |
| 108 | } |
You Wang | 4023945 | 2020-06-11 20:17:15 -0700 | [diff] [blame] | 109 | } |
| 110 | } |
| 111 | |
You Wang | ae518b5 | 2020-09-21 16:29:25 -0700 | [diff] [blame] | 112 | stage ("Update aether-pod-configs"){ |
| 113 | steps { |
| 114 | build job: "aether-member-only-jobs/aether-postmerge", parameters: [ |
| 115 | string(name: 'repoName', value: "${repoName}"), |
| 116 | string(name: 'images', value: "${updatedImages}"), |
| 117 | ] |
| 118 | } |
| 119 | } |
| 120 | |
You Wang | 2a8a91b | 2020-06-15 13:34:22 -0700 | [diff] [blame] | 121 | stage ("Deploy and Test"){ |
| 122 | options { |
| 123 | lock(resource: 'aether-dev-cluster') |
| 124 | } |
| 125 | |
| 126 | stages { |
| 127 | stage ("Deploy OMEC"){ |
| 128 | steps { |
You Wang | ae518b5 | 2020-09-21 16:29:25 -0700 | [diff] [blame] | 129 | echo "Using hssdb image: ${hssdb_image}" |
| 130 | echo "Using hss image: ${hss_image}" |
| 131 | echo "Using mme image: ${mme_image}" |
| 132 | echo "Using spgwc image: ${spgwc_image}" |
| 133 | echo "Using bess image: ${bess_image}" |
| 134 | echo "Using zmqiface image: ${zmqiface_image}" |
| 135 | echo "Using pfcpiface image: ${pfcpiface_image}" |
You Wang | 2a8a91b | 2020-06-15 13:34:22 -0700 | [diff] [blame] | 136 | build job: "omec_deploy_dev", parameters: [ |
| 137 | string(name: 'hssdbImage', value: "${hssdb_image.trim()}"), |
| 138 | string(name: 'hssImage', value: "${hss_image.trim()}"), |
| 139 | string(name: 'mmeImage', value: "${mme_image.trim()}"), |
| 140 | string(name: 'spgwcImage', value: "${spgwc_image.trim()}"), |
You Wang | e1cbba2 | 2020-06-15 21:16:14 -0700 | [diff] [blame] | 141 | string(name: 'bessImage', value: "${bess_image.trim()}"), |
You Wang | 425d49f | 2020-07-29 21:43:28 -0700 | [diff] [blame] | 142 | string(name: 'zmqifaceImage', value: "${zmqiface_image.trim()}"), |
| 143 | string(name: 'pfcpifaceImage', value: "${pfcpiface_image.trim()}"), |
You Wang | 2a8a91b | 2020-06-15 13:34:22 -0700 | [diff] [blame] | 144 | ] |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | stage ("Run NG40 Tests"){ |
| 149 | steps { |
| 150 | build job: "omec_ng40-test_dev" |
| 151 | } |
| 152 | } |
You Wang | 5c15a7a | 2020-04-02 11:24:33 -0700 | [diff] [blame] | 153 | } |
| 154 | } |
| 155 | } |
| 156 | post { |
| 157 | failure { |
| 158 | step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "${params.maintainers}", sendToIndividuals: false]) |
| 159 | } |
| 160 | } |
| 161 | } |