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 { |
| 29 | abbreviated_commit_hash = commitHash.substring(0, 7) |
Jeremy Ronquillo | 6e42f8c | 2020-04-27 14:13:51 -0700 | [diff] [blame] | 30 | tags_to_build = [ "${branchName}-latest", |
| 31 | "${branchName}-${abbreviated_commit_hash}"] |
| 32 | tags_to_build.each { tag -> |
| 33 | build job: "docker-publish-github_$repoName", parameters: [ |
| 34 | string(name: 'gitUrl', value: "${repoUrl}"), |
| 35 | string(name: 'gitRef', value: "${branchName}"), |
| 36 | string(name: 'branchName', value: "${tag}"), |
| 37 | string(name: 'projectName', value: "${repoName}"), |
| 38 | ] |
| 39 | } |
Jeremy Ronquillo | d91e308 | 2020-04-09 11:32:41 -0700 | [diff] [blame] | 40 | } |
You Wang | 5c15a7a | 2020-04-02 11:24:33 -0700 | [diff] [blame] | 41 | } |
| 42 | } |
| 43 | |
You Wang | 2a8a91b | 2020-06-15 13:34:22 -0700 | [diff] [blame] | 44 | stage ("Prepare OMEC deployment"){ |
You Wang | 5c15a7a | 2020-04-02 11:24:33 -0700 | [diff] [blame] | 45 | steps { |
| 46 | script { |
| 47 | hssdb_tag = sh returnStdout: true, script: """curl -s 'https://registry.hub.docker.com/v2/repositories/omecproject/c3po-hssdb/tags/' | jq '.results[] | select(.name | contains("${c3poBranchName}")).name' | head -1 | tr -d \\\"""" |
| 48 | hss_tag = sh returnStdout: true, script: """curl -s 'https://registry.hub.docker.com/v2/repositories/omecproject/c3po-hss/tags/' | jq '.results[] | select(.name | contains("${c3poBranchName}")).name' | head -1 | tr -d \\\"""" |
You Wang | 4023945 | 2020-06-11 20:17:15 -0700 | [diff] [blame] | 49 | mme_tag = sh returnStdout: true, script: """curl -s 'https://registry.hub.docker.com/v2/repositories/omecproject/nucleus/tags/' | jq '.results[] | select(.name | contains("${nucleusBranchName}")).name' | head -1 | tr -d \\\"""" |
You Wang | 5c15a7a | 2020-04-02 11:24:33 -0700 | [diff] [blame] | 50 | spgwc_tag = sh returnStdout: true, script: """curl -s 'https://registry.hub.docker.com/v2/repositories/omecproject/ngic-cp/tags/' | jq '.results[] | select(.name | contains("${ngicBranchName}")).name' | head -1 | tr -d \\\"""" |
| 51 | spgwu_tag = sh returnStdout: true, script: """curl -s 'https://registry.hub.docker.com/v2/repositories/omecproject/ngic-dp/tags/' | jq '.results[] | select(.name | contains("${ngicBranchName}")).name' | head -1 | tr -d \\\"""" |
You Wang | 4023945 | 2020-06-11 20:17:15 -0700 | [diff] [blame] | 52 | |
| 53 | hssdb_image = "omecproject/c3po-hssdb:"+hssdb_tag |
| 54 | hss_image = "omecproject/c3po-hss:"+hss_tag |
| 55 | mme_image = "omecproject/nucleus:"+mme_tag |
| 56 | spgwc_image = "omecproject/ngic-cp:"+spgwc_tag |
| 57 | spgwu_image = "omecproject/ngic-dp:"+spgwu_tag |
| 58 | |
You Wang | 5c15a7a | 2020-04-02 11:24:33 -0700 | [diff] [blame] | 59 | switch("${params.repoName}") { |
| 60 | case "c3po": |
You Wang | 4023945 | 2020-06-11 20:17:15 -0700 | [diff] [blame] | 61 | hssdb_image = "${params.registry}/c3po-hssdb:${branchName}-${abbreviated_commit_hash}" |
| 62 | hss_image = "${params.registry}/c3po-hss:${branchName}-${abbreviated_commit_hash}" |
You Wang | 5c15a7a | 2020-04-02 11:24:33 -0700 | [diff] [blame] | 63 | break |
| 64 | case "ngic-rtc": |
You Wang | 4023945 | 2020-06-11 20:17:15 -0700 | [diff] [blame] | 65 | spgwc_image = "${params.registry}/ngic-cp:${branchName}-${abbreviated_commit_hash}" |
| 66 | spgwu_image = "${params.registry}/ngic-dp:${branchName}-${abbreviated_commit_hash}" |
You Wang | 5c15a7a | 2020-04-02 11:24:33 -0700 | [diff] [blame] | 67 | break |
You Wang | 4023945 | 2020-06-11 20:17:15 -0700 | [diff] [blame] | 68 | case "Nucleus": |
| 69 | mme_image = "${params.registry}/nucleus:${branchName}-${abbreviated_commit_hash}" |
You Wang | 5c15a7a | 2020-04-02 11:24:33 -0700 | [diff] [blame] | 70 | break |
| 71 | } |
You Wang | 4023945 | 2020-06-11 20:17:15 -0700 | [diff] [blame] | 72 | echo "Using hssdb image: ${hssdb_image}" |
| 73 | echo "Using hss image: ${hss_image}" |
| 74 | echo "Using mme image: ${mme_image}" |
| 75 | echo "Using spgwc image: ${spgwc_image}" |
| 76 | echo "Using spgwu image: ${spgwu_image}" |
You Wang | 5c15a7a | 2020-04-02 11:24:33 -0700 | [diff] [blame] | 77 | } |
You Wang | 4023945 | 2020-06-11 20:17:15 -0700 | [diff] [blame] | 78 | } |
| 79 | } |
| 80 | |
You Wang | 2a8a91b | 2020-06-15 13:34:22 -0700 | [diff] [blame] | 81 | stage ("Deploy and Test"){ |
| 82 | options { |
| 83 | lock(resource: 'aether-dev-cluster') |
| 84 | } |
| 85 | |
| 86 | stages { |
| 87 | stage ("Deploy OMEC"){ |
| 88 | steps { |
| 89 | build job: "omec_deploy_dev", parameters: [ |
| 90 | string(name: 'hssdbImage', value: "${hssdb_image.trim()}"), |
| 91 | string(name: 'hssImage', value: "${hss_image.trim()}"), |
| 92 | string(name: 'mmeImage', value: "${mme_image.trim()}"), |
| 93 | string(name: 'spgwcImage', value: "${spgwc_image.trim()}"), |
| 94 | string(name: 'spgwuImage', value: "${spgwu_image.trim()}"), |
| 95 | ] |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | stage ("Run NG40 Tests"){ |
| 100 | steps { |
| 101 | build job: "omec_ng40-test_dev" |
| 102 | } |
| 103 | } |
You Wang | 5c15a7a | 2020-04-02 11:24:33 -0700 | [diff] [blame] | 104 | } |
| 105 | } |
| 106 | } |
| 107 | post { |
| 108 | failure { |
| 109 | step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "${params.maintainers}", sendToIndividuals: false]) |
| 110 | } |
| 111 | } |
| 112 | } |