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 |
| 16 | // Combines docker-publish and deploy-staging pipelines into one job that can be triggered by a GitHub PR merge |
| 17 | |
| 18 | def hssdb_tag = "" |
| 19 | def hss_tag = "" |
| 20 | def mme_tag = "" |
| 21 | def spgwc_tag = "" |
| 22 | def spgwu_tag = "" |
Jeremy Ronquillo | d91e308 | 2020-04-09 11:32:41 -0700 | [diff] [blame] | 23 | def abbreviated_commit_hash = "" |
Jeremy Ronquillo | e65e9a9 | 2020-04-08 16:27:55 -0700 | [diff] [blame] | 24 | def quietPeriodTime = 0 |
You Wang | 5c15a7a | 2020-04-02 11:24:33 -0700 | [diff] [blame] | 25 | |
| 26 | pipeline { |
| 27 | |
| 28 | agent { |
| 29 | label "${params.buildNode}" |
| 30 | } |
| 31 | |
| 32 | stages { |
| 33 | |
| 34 | stage('Publish') { |
| 35 | steps { |
Jeremy Ronquillo | d91e308 | 2020-04-09 11:32:41 -0700 | [diff] [blame] | 36 | script { |
| 37 | abbreviated_commit_hash = commitHash.substring(0, 7) |
Jeremy Ronquillo | 6e42f8c | 2020-04-27 14:13:51 -0700 | [diff] [blame] | 38 | tags_to_build = [ "${branchName}-latest", |
| 39 | "${branchName}-${abbreviated_commit_hash}"] |
| 40 | tags_to_build.each { tag -> |
| 41 | build job: "docker-publish-github_$repoName", parameters: [ |
| 42 | string(name: 'gitUrl', value: "${repoUrl}"), |
| 43 | string(name: 'gitRef', value: "${branchName}"), |
| 44 | string(name: 'branchName', value: "${tag}"), |
| 45 | string(name: 'projectName', value: "${repoName}"), |
| 46 | ] |
| 47 | } |
Jeremy Ronquillo | d91e308 | 2020-04-09 11:32:41 -0700 | [diff] [blame] | 48 | } |
You Wang | 5c15a7a | 2020-04-02 11:24:33 -0700 | [diff] [blame] | 49 | } |
| 50 | } |
| 51 | |
| 52 | stage('Deploy') { |
| 53 | steps { |
| 54 | script { |
| 55 | 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 \\\"""" |
| 56 | 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 \\\"""" |
| 57 | mme_tag = sh returnStdout: true, script: """curl -s 'https://registry.hub.docker.com/v2/repositories/omecproject/openmme/tags/' | jq '.results[] | select(.name | contains("${openmmeBranchName}")).name' | head -1 | tr -d \\\"""" |
| 58 | 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 \\\"""" |
| 59 | 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 \\\"""" |
| 60 | switch("${params.repoName}") { |
| 61 | case "c3po": |
Jeremy Ronquillo | d91e308 | 2020-04-09 11:32:41 -0700 | [diff] [blame] | 62 | hssdb_tag = "${branchName}-${abbreviated_commit_hash}" |
| 63 | hss_tag = "${branchName}-${abbreviated_commit_hash}" |
You Wang | 5c15a7a | 2020-04-02 11:24:33 -0700 | [diff] [blame] | 64 | break |
| 65 | case "ngic-rtc": |
Jeremy Ronquillo | d91e308 | 2020-04-09 11:32:41 -0700 | [diff] [blame] | 66 | spgwc_tag = "${branchName}-${abbreviated_commit_hash}" |
| 67 | spgwu_tag = "${branchName}-${abbreviated_commit_hash}" |
You Wang | 5c15a7a | 2020-04-02 11:24:33 -0700 | [diff] [blame] | 68 | break |
| 69 | case "openmme": |
Jeremy Ronquillo | d91e308 | 2020-04-09 11:32:41 -0700 | [diff] [blame] | 70 | mme_tag = "${branchName}-${abbreviated_commit_hash}" |
You Wang | 5c15a7a | 2020-04-02 11:24:33 -0700 | [diff] [blame] | 71 | break |
| 72 | } |
Jeremy Ronquillo | e65e9a9 | 2020-04-08 16:27:55 -0700 | [diff] [blame] | 73 | // Add quiet period to downstream job. This is to delay running the |
| 74 | // deploy staging job until midnight, so it will not interrupt any |
| 75 | // development on the staging cluster during the day. |
| 76 | def now = Math.floor((new Date()).getTime() / 1000.0) // Get current time in seconds |
| 77 | def PDTOffset = 25200 // PDT Offset from UTC in seconds |
| 78 | def oneDay = 86400 // 24 hours in seconds |
| 79 | quietPeriodTime = oneDay - (now - PDTOffset) % oneDay // number of seconds until next midnight |
| 80 | println "Quiet Period (seconds until next midnight): " + quietPeriodTime |
You Wang | 5c15a7a | 2020-04-02 11:24:33 -0700 | [diff] [blame] | 81 | } |
| 82 | build job: "omec-deploy-staging", parameters: [ |
Jeremy Ronquillo | 3d4f714 | 2020-04-23 12:25:47 -0700 | [diff] [blame] | 83 | string(name: 'hssdb_tag', value: "${hssdb_tag.trim()}"), |
| 84 | string(name: 'hss_tag', value: "${hss_tag.trim()}"), |
| 85 | string(name: 'mme_tag', value: "${mme_tag.trim()}"), |
| 86 | string(name: 'spgwc_tag', value: "${spgwc_tag.trim()}"), |
| 87 | string(name: 'spgwu_tag', value: "${spgwu_tag.trim()}"), |
Jeremy Ronquillo | e65e9a9 | 2020-04-08 16:27:55 -0700 | [diff] [blame] | 88 | ], quietPeriod: quietPeriodTime |
You Wang | 5c15a7a | 2020-04-02 11:24:33 -0700 | [diff] [blame] | 89 | } |
| 90 | } |
| 91 | } |
| 92 | post { |
| 93 | failure { |
| 94 | step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "${params.maintainers}", sendToIndividuals: false]) |
| 95 | } |
| 96 | } |
| 97 | } |