blob: db3a89b6ae82681b18a9e1fda485fd860e072561 [file] [log] [blame]
Jonathan Hart93be2a02017-12-04 09:23:34 -08001// 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 Hart8d253832017-12-04 08:57:29 -080014
Jonathan Hart7b395df2017-12-04 10:07:17 -080015def app = '${app}'
16def version = '${version}'
Jonathan Hart5cbd2d72017-12-04 13:45:19 -080017def nextVersion = '${nextVersion}'
Jonathan Hart7b395df2017-12-04 10:07:17 -080018def branch = '${branch}'
Jonathan Hart8d253832017-12-04 08:57:29 -080019
20def 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
25int 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 Hart2b564992017-12-04 14:07:25 -080034def changeVersion(def newVersion) {
Jonathan Hart5cbd2d72017-12-04 13:45:19 -080035 // TODO any other versions we need to account for?
36 sh 'mvn versions:set -DnewVersion=' + newVersion + ' versions:commit'
37}
38
Jonathan Hart8d253832017-12-04 08:57:29 -080039node ('master') {
Jonathan Hart69938f52017-12-04 14:10:59 -080040 stage ('Checkout code') {
Jonathan Hart5cbd2d72017-12-04 13:45:19 -080041 //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 Hart8d253832017-12-04 08:57:29 -080044
45
Jonathan Hart93be2a02017-12-04 09:23:34 -080046 //stage 'Create support branch'
Jonathan Hart93be2a02017-12-04 09:23:34 -080047 //if (checkBranchExists(app, branch) == 0) {
Jonathan Hart7b395df2017-12-04 10:07:17 -080048 // 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 Hart69938f52017-12-04 14:10:59 -080054 stage ('Checkout branch') {
Jonathan Hart5cbd2d72017-12-04 13:45:19 -080055 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 Hart7b395df2017-12-04 10:07:17 -080057 }
Jonathan Hart5cbd2d72017-12-04 13:45:19 -080058
Jonathan Hart69938f52017-12-04 14:10:59 -080059 stage ('Bump versions') {
Jonathan Hart5cbd2d72017-12-04 13:45:19 -080060 changeVersion(version)
61 }
Jonathan Hart8d253832017-12-04 08:57:29 -080062
Jonathan Hart69938f52017-12-04 14:10:59 -080063 stage ('Commit') {
Jonathan Hart5cbd2d72017-12-04 13:45:19 -080064 sh 'git add -A && git commit -m "Release version ' + version + '"'
65 }
Jonathan Hart8d253832017-12-04 08:57:29 -080066
Jonathan Hart69938f52017-12-04 14:10:59 -080067 stage ('Build and Test') {
Jonathan Hart5cbd2d72017-12-04 13:45:19 -080068 // TODO can we do this with clean .m2?
69 sh 'mvn clean install'
70 }
71
Jonathan Hart69938f52017-12-04 14:10:59 -080072 stage ('Push to Gerrit') {
Jonathan Hart5cbd2d72017-12-04 13:45:19 -080073 sh 'git push origin HEAD:refs/for/' + branch
74 }
Jonathan Hart8d253832017-12-04 08:57:29 -080075
Jonathan Hart69938f52017-12-04 14:10:59 -080076 stage ('Wait for merge') {
Jonathan Hart5cbd2d72017-12-04 13:45:19 -080077 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
Jonathan Hart69938f52017-12-04 14:10:59 -080083 stage ('Release to Maven Central') {
Jonathan Hart5cbd2d72017-12-04 13:45:19 -080084 sh 'mvn -Prelease clean deploy'
85 }
86
Jonathan Hart69938f52017-12-04 14:10:59 -080087 stage ('Wait for release OKed') {
Jonathan Hart5cbd2d72017-12-04 13:45:19 -080088 timeout(time: 1, unit: 'HOURS') {
89 metadata = input id: 'release-build', message: 'Release the artifacts on Sonatype',
90 submitter: 'jono'
91 }
92 }
93
Jonathan Hart69938f52017-12-04 14:10:59 -080094 stage ('Tag the release') {
Jonathan Hart5cbd2d72017-12-04 13:45:19 -080095 sh 'git tag -a ' + version + ' -m "Tagging version ' + version + '"'
96 sh 'git push origin ' + version
97 }
98
Jonathan Hart69938f52017-12-04 14:10:59 -080099 stage ('Move to next SNAPSHOT version') {
Jonathan Hart5cbd2d72017-12-04 13:45:19 -0800100 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
Jonathan Hart69938f52017-12-04 14:10:59 -0800106 stage ('Finish') {
Jonathan Hart5cbd2d72017-12-04 13:45:19 -0800107 sh 'echo "Released new app. Go to Gerrit and merge snapshot version bump"'
108 }
109
Jonathan Hart8d253832017-12-04 08:57:29 -0800110}