blob: a76adafdd537dd54ed9c2835c46a3f7e10adc571 [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 Hartdfa51952017-12-04 14:39:28 -080040 stage ('Clean workspace') {
41 cleanWs()
42 }
43
Jonathan Hart69938f52017-12-04 14:10:59 -080044 stage ('Checkout code') {
Jonathan Hart5cbd2d72017-12-04 13:45:19 -080045 //checkout([$class: 'RepoScm', currentBranch: true, manifestRepositoryUrl: 'https://gerrit.opencord.org/manifest', quiet: true])
46 git branch: branch, url: 'ssh://jenkins@gerrit.opencord.org:29418/' + app
47 }
Jonathan Hart8d253832017-12-04 08:57:29 -080048
49
Jonathan Hart93be2a02017-12-04 09:23:34 -080050 //stage 'Create support branch'
Jonathan Hart93be2a02017-12-04 09:23:34 -080051 //if (checkBranchExists(app, branch) == 0) {
Jonathan Hart7b395df2017-12-04 10:07:17 -080052 // echo "Branch " + branch + " doesn't exist, creating
53 //createBranch(app, version, 'opencord/master')
54 //} else {
55 // echo "Support branch " + branch + " already exists"
56 //}
57
Jonathan Hart69938f52017-12-04 14:10:59 -080058 stage ('Checkout branch') {
Jonathan Hart5cbd2d72017-12-04 13:45:19 -080059 sh 'git checkout ' + branch
60 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 -080061 }
Jonathan Hart5cbd2d72017-12-04 13:45:19 -080062
Jonathan Hart69938f52017-12-04 14:10:59 -080063 stage ('Bump versions') {
Jonathan Hart5cbd2d72017-12-04 13:45:19 -080064 changeVersion(version)
65 }
Jonathan Hart8d253832017-12-04 08:57:29 -080066
Jonathan Hart69938f52017-12-04 14:10:59 -080067 stage ('Commit') {
Jonathan Hart5cbd2d72017-12-04 13:45:19 -080068 sh 'git add -A && git commit -m "Release version ' + version + '"'
69 }
Jonathan Hart8d253832017-12-04 08:57:29 -080070
Jonathan Hart69938f52017-12-04 14:10:59 -080071 stage ('Build and Test') {
Jonathan Hart5cbd2d72017-12-04 13:45:19 -080072 // TODO can we do this with clean .m2?
73 sh 'mvn clean install'
74 }
75
Jonathan Hart69938f52017-12-04 14:10:59 -080076 stage ('Push to Gerrit') {
Jonathan Hart5cbd2d72017-12-04 13:45:19 -080077 sh 'git push origin HEAD:refs/for/' + branch
78 }
Jonathan Hart8d253832017-12-04 08:57:29 -080079
Jonathan Hart69938f52017-12-04 14:10:59 -080080 stage ('Wait for merge') {
Jonathan Hart5cbd2d72017-12-04 13:45:19 -080081 timeout(time: 1, unit: 'HOURS') {
82 metadata = input id: 'release-build', message: 'Go to Gerrit and merge the release patch',
83 submitter: 'jono'
84 }
85 }
86
Jonathan Hart69938f52017-12-04 14:10:59 -080087 stage ('Release to Maven Central') {
Jonathan Hart5cbd2d72017-12-04 13:45:19 -080088 sh 'mvn -Prelease clean deploy'
89 }
90
Jonathan Hart69938f52017-12-04 14:10:59 -080091 stage ('Wait for release OKed') {
Jonathan Hart5cbd2d72017-12-04 13:45:19 -080092 timeout(time: 1, unit: 'HOURS') {
93 metadata = input id: 'release-build', message: 'Release the artifacts on Sonatype',
94 submitter: 'jono'
95 }
96 }
97
Jonathan Hart69938f52017-12-04 14:10:59 -080098 stage ('Tag the release') {
Jonathan Hart5cbd2d72017-12-04 13:45:19 -080099 sh 'git tag -a ' + version + ' -m "Tagging version ' + version + '"'
100 sh 'git push origin ' + version
101 }
102
Jonathan Hart69938f52017-12-04 14:10:59 -0800103 stage ('Move to next SNAPSHOT version') {
Jonathan Hart5cbd2d72017-12-04 13:45:19 -0800104 def snapshot = nextVersion + '-SNAPSHOT'
105 changeVersion(snapshot)
106 sh 'git add -A && git commit -m "Starting snapshot ' + snapshot + '"'
107 sh 'git push origin HEAD:refs/for/' + branch
108 }
109
Jonathan Hart69938f52017-12-04 14:10:59 -0800110 stage ('Finish') {
Jonathan Hart5cbd2d72017-12-04 13:45:19 -0800111 sh 'echo "Released new app. Go to Gerrit and merge snapshot version bump"'
112 }
113
Jonathan Hart8d253832017-12-04 08:57:29 -0800114}