Jonathan Hart | 93be2a0 | 2017-12-04 09:23:34 -0800 | [diff] [blame] | 1 | // Copyright 2017-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. |
Jonathan Hart | 8d25383 | 2017-12-04 08:57:29 -0800 | [diff] [blame] | 14 | |
Jonathan Hart | 7b395df | 2017-12-04 10:07:17 -0800 | [diff] [blame] | 15 | def app = '${app}' |
| 16 | def version = '${version}' |
Jonathan Hart | 5cbd2d7 | 2017-12-04 13:45:19 -0800 | [diff] [blame^] | 17 | def nextVersion = '${nextVersion}' |
Jonathan Hart | 7b395df | 2017-12-04 10:07:17 -0800 | [diff] [blame] | 18 | def branch = '${branch}' |
Jonathan Hart | 8d25383 | 2017-12-04 08:57:29 -0800 | [diff] [blame] | 19 | |
| 20 | def createBranch(def proj, def branch, def parent) { |
| 21 | cmd = 'ssh -p 29418 gerrit.opencord.org gerrit create-branch ' + proj + " " + branch + " " + parent |
| 22 | sh returnStdout: true, script: cmd |
| 23 | } |
| 24 | |
| 25 | int checkBranchExists(def proj, def branch) { |
| 26 | url = 'https://gerrit.opencord.org/projects/' + proj + '/branches/' + branch |
| 27 | response = httpRequest url: url, validResponseCodes: '200,404' |
| 28 | if (response.status == 404) { |
| 29 | return 1 |
| 30 | } |
| 31 | return 0 |
| 32 | } |
| 33 | |
Jonathan Hart | 5cbd2d7 | 2017-12-04 13:45:19 -0800 | [diff] [blame^] | 34 | def changeVersion(dev newVersion) { |
| 35 | // TODO any other versions we need to account for? |
| 36 | sh 'mvn versions:set -DnewVersion=' + newVersion + ' versions:commit' |
| 37 | } |
| 38 | |
Jonathan Hart | 8d25383 | 2017-12-04 08:57:29 -0800 | [diff] [blame] | 39 | node ('master') { |
Jonathan Hart | 5cbd2d7 | 2017-12-04 13:45:19 -0800 | [diff] [blame^] | 40 | stage 'Checkout code' { |
| 41 | //checkout([$class: 'RepoScm', currentBranch: true, manifestRepositoryUrl: 'https://gerrit.opencord.org/manifest', quiet: true]) |
| 42 | git branch: branch, url: 'ssh://jenkins@gerrit.opencord.org:29418/' + app |
| 43 | } |
Jonathan Hart | 8d25383 | 2017-12-04 08:57:29 -0800 | [diff] [blame] | 44 | |
| 45 | |
Jonathan Hart | 93be2a0 | 2017-12-04 09:23:34 -0800 | [diff] [blame] | 46 | //stage 'Create support branch' |
Jonathan Hart | 93be2a0 | 2017-12-04 09:23:34 -0800 | [diff] [blame] | 47 | //if (checkBranchExists(app, branch) == 0) { |
Jonathan Hart | 7b395df | 2017-12-04 10:07:17 -0800 | [diff] [blame] | 48 | // echo "Branch " + branch + " doesn't exist, creating |
| 49 | //createBranch(app, version, 'opencord/master') |
| 50 | //} else { |
| 51 | // echo "Support branch " + branch + " already exists" |
| 52 | //} |
| 53 | |
Jonathan Hart | 5cbd2d7 | 2017-12-04 13:45:19 -0800 | [diff] [blame^] | 54 | stage 'Checkout branch' { |
| 55 | sh 'git checkout ' + branch |
| 56 | sh 'gitdir=$(git rev-parse --git-dir); scp -p -P 29418 jenkins@gerrit.opencord.org:hooks/commit-msg ${gitdir}/hooks/' |
Jonathan Hart | 7b395df | 2017-12-04 10:07:17 -0800 | [diff] [blame] | 57 | } |
Jonathan Hart | 5cbd2d7 | 2017-12-04 13:45:19 -0800 | [diff] [blame^] | 58 | |
| 59 | stage 'Bump versions' { |
| 60 | changeVersion(version) |
| 61 | } |
Jonathan Hart | 8d25383 | 2017-12-04 08:57:29 -0800 | [diff] [blame] | 62 | |
Jonathan Hart | 5cbd2d7 | 2017-12-04 13:45:19 -0800 | [diff] [blame^] | 63 | stage 'Commit' { |
| 64 | sh 'git add -A && git commit -m "Release version ' + version + '"' |
| 65 | } |
Jonathan Hart | 8d25383 | 2017-12-04 08:57:29 -0800 | [diff] [blame] | 66 | |
Jonathan Hart | 5cbd2d7 | 2017-12-04 13:45:19 -0800 | [diff] [blame^] | 67 | stage 'Build and Test' { |
| 68 | // TODO can we do this with clean .m2? |
| 69 | sh 'mvn clean install' |
| 70 | } |
| 71 | |
| 72 | stage 'Push to Gerrit' { |
| 73 | sh 'git push origin HEAD:refs/for/' + branch |
| 74 | } |
Jonathan Hart | 8d25383 | 2017-12-04 08:57:29 -0800 | [diff] [blame] | 75 | |
Jonathan Hart | 5cbd2d7 | 2017-12-04 13:45:19 -0800 | [diff] [blame^] | 76 | stage 'Wait for merge' { |
| 77 | timeout(time: 1, unit: 'HOURS') { |
| 78 | metadata = input id: 'release-build', message: 'Go to Gerrit and merge the release patch', |
| 79 | submitter: 'jono' |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | stage 'Release to Maven Central' { |
| 84 | sh 'mvn -Prelease clean deploy' |
| 85 | } |
| 86 | |
| 87 | stage 'Wait for release OKed' { |
| 88 | timeout(time: 1, unit: 'HOURS') { |
| 89 | metadata = input id: 'release-build', message: 'Release the artifacts on Sonatype', |
| 90 | submitter: 'jono' |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | stage 'Tag the release' { |
| 95 | sh 'git tag -a ' + version + ' -m "Tagging version ' + version + '"' |
| 96 | sh 'git push origin ' + version |
| 97 | } |
| 98 | |
| 99 | stage 'Move to next SNAPSHOT version' { |
| 100 | def snapshot = nextVersion + '-SNAPSHOT' |
| 101 | changeVersion(snapshot) |
| 102 | sh 'git add -A && git commit -m "Starting snapshot ' + snapshot + '"' |
| 103 | sh 'git push origin HEAD:refs/for/' + branch |
| 104 | } |
| 105 | |
| 106 | stage 'Finish' { |
| 107 | sh 'echo "Released new app. Go to Gerrit and merge snapshot version bump"' |
| 108 | } |
| 109 | |
Jonathan Hart | 8d25383 | 2017-12-04 08:57:29 -0800 | [diff] [blame] | 110 | } |