blob: 0e26b02c831303e79c0847294a9d6214bcaba5cd [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 Hart5cbd2d72017-12-04 13:45:19 -080034def 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 Hart8d253832017-12-04 08:57:29 -080039node ('master') {
Jonathan Hart5cbd2d72017-12-04 13:45:19 -080040 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 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 Hart5cbd2d72017-12-04 13:45:19 -080054 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 Hart7b395df2017-12-04 10:07:17 -080057 }
Jonathan Hart5cbd2d72017-12-04 13:45:19 -080058
59 stage 'Bump versions' {
60 changeVersion(version)
61 }
Jonathan Hart8d253832017-12-04 08:57:29 -080062
Jonathan Hart5cbd2d72017-12-04 13:45:19 -080063 stage 'Commit' {
64 sh 'git add -A && git commit -m "Release version ' + version + '"'
65 }
Jonathan Hart8d253832017-12-04 08:57:29 -080066
Jonathan Hart5cbd2d72017-12-04 13:45:19 -080067 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 Hart8d253832017-12-04 08:57:29 -080075
Jonathan Hart5cbd2d72017-12-04 13:45:19 -080076 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 Hart8d253832017-12-04 08:57:29 -0800110}