blob: 03eb0b9d652d3a2e5b9d1aa2f4f98423417ecc93 [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
Jonathan Hart2b564992017-12-04 14:07:25 -080020def changeVersion(def newVersion) {
Jonathan Hart5cbd2d72017-12-04 13:45:19 -080021 // TODO any other versions we need to account for?
22 sh 'mvn versions:set -DnewVersion=' + newVersion + ' versions:commit'
23}
24
Jonathan Hart6c0cca02018-05-29 10:43:30 -070025node ('ubuntu16.04-basebuild-1c-2g') {
Jonathan Hart99ce7ff2018-05-30 14:46:00 -070026
27 sh 'echo Releasing ' + app + ' repository on ' + branch + ' branch'
28 sh 'echo Releasing version ' + version + ' and starting ' + nextVersion + '-SNAPSHOT'
29
30 def userId = wrap([$class: 'BuildUser']) {
31 return env.BUILD_USER_ID
32 }
Jonathan Hart8d253832017-12-04 08:57:29 -080033
Jonathan Hartb9615f22018-05-30 10:56:01 -070034 stage ('Configure system') {
Jonathan Hart99ce7ff2018-05-30 14:46:00 -070035 echo "Release build triggered by " + userId
36
Jonathan Hart20225d82018-05-29 18:38:19 -070037 sh 'ssh-keyscan -H -t rsa -p 29418 gerrit.opencord.org >> ~/.ssh/known_hosts'
38
39 sh 'git config --global user.name "Jenkins"'
40 sh 'git config --global user.email "do-not-reply@opencord.org"'
Jonathan Hartb9615f22018-05-30 10:56:01 -070041
Jonathan Hart99ce7ff2018-05-30 14:46:00 -070042 // GPG key used to sign maven artifacts
Jonathan Hartb9615f22018-05-30 10:56:01 -070043 withCredentials([file(credentialsId: 'gpg-creds-maven', variable: 'GPUPG')]) {
44 sh 'tar -xvf $GPUPG -C ~'
45 }
Jonathan Hart145b5112018-05-29 16:16:56 -070046 }
47
Jonathan Hartb9615f22018-05-30 10:56:01 -070048 stage ('Check out code') {
Jonathan Hart7942fa02017-12-04 15:43:00 -080049 cleanWs()
Jonathan Hart20225d82018-05-29 18:38:19 -070050
51 sshagent (credentials: ['gerrit-jenkins-user']) {
52 git branch: branch, url: 'ssh://jenkins@gerrit.opencord.org:29418/' + app, credentialsId: 'gerrit-jenkins-user'
Jonathan Hart7942fa02017-12-04 15:43:00 -080053
Jonathan Hart20225d82018-05-29 18:38:19 -070054 sh 'gitdir=$(git rev-parse --git-dir); scp -p -P 29418 jenkins@gerrit.opencord.org:hooks/commit-msg ${gitdir}/hooks/'
55 }
Jonathan Hart7b395df2017-12-04 10:07:17 -080056 }
Jonathan Hart5cbd2d72017-12-04 13:45:19 -080057
Jonathan Hart7942fa02017-12-04 15:43:00 -080058 stage ('Move to release version') {
Jonathan Hart5cbd2d72017-12-04 13:45:19 -080059 changeVersion(version)
Jonathan Hart5cbd2d72017-12-04 13:45:19 -080060 sh 'git add -A && git commit -m "Release version ' + version + '"'
61 }
Jonathan Hartb9615f22018-05-30 10:56:01 -070062
Jonathan Hart20225d82018-05-29 18:38:19 -070063 stage ('Verify code') {
Jonathan Hart55bef2c2018-05-29 18:40:37 -070064 def found = sh script:'egrep -R SNAPSHOT .', returnStatus:true
Jonathan Hartb9615f22018-05-30 10:56:01 -070065
Jonathan Hart20225d82018-05-29 18:38:19 -070066 if (found == 0) {
67 timeout(time: 1, unit: 'HOURS') {
68 metadata = input id: 'manual-verify',
69 message: 'Found references to SNAPSHOT in the code. Are you sure you want to release?',
Jonathan Hart99ce7ff2018-05-30 14:46:00 -070070 submitter: userId
Jonathan Hart20225d82018-05-29 18:38:19 -070071 }
72 }
73 }
Jonathan Hart8d253832017-12-04 08:57:29 -080074
Jonathan Hart7942fa02017-12-04 15:43:00 -080075 // This step is basically to test that everything still builds once the version has
76 // been bumped up before we start pushing things publicly
Jonathan Hart69938f52017-12-04 14:10:59 -080077 stage ('Build and Test') {
Jonathan Hart5cbd2d72017-12-04 13:45:19 -080078 sh 'mvn clean install'
Jonathan Hart7942fa02017-12-04 15:43:00 -080079 sh 'mvn javadoc:javadoc'
Jonathan Hart5cbd2d72017-12-04 13:45:19 -080080 }
81
Jonathan Hart69938f52017-12-04 14:10:59 -080082 stage ('Push to Gerrit') {
Jonathan Hart20225d82018-05-29 18:38:19 -070083 sshagent (credentials: ['gerrit-jenkins-user']) {
84 sh 'git push origin HEAD:refs/for/' + branch
85 }
Jonathan Hart5cbd2d72017-12-04 13:45:19 -080086 }
Jonathan Hart8d253832017-12-04 08:57:29 -080087
Jonathan Hart69938f52017-12-04 14:10:59 -080088 stage ('Wait for merge') {
Jonathan Harta85af1e2018-05-30 11:54:47 -070089 timeout(time: 1, unit: 'HOURS') {
90 metadata = input id: 'release-build',
91 message: 'Go to Gerrit and merge the release patch',
Jonathan Hart99ce7ff2018-05-30 14:46:00 -070092 submitter: userId
Jonathan Hart5cbd2d72017-12-04 13:45:19 -080093 }
Jonathan Hart99ce7ff2018-05-30 14:46:00 -070094
Jonathan Hart5cbd2d72017-12-04 13:45:19 -080095 }
96
Jonathan Hart99ce7ff2018-05-30 14:46:00 -070097 stage ('Release artifacts') {
Jonathan Hart6c0cca02018-05-29 10:43:30 -070098 configFileProvider([configFile(fileId: 'onoscord-apps', variable: 'MAVEN_SETTINGS')]) {
99 sh 'mvn -s $MAVEN_SETTINGS -Prelease clean deploy'
100 }
Jonathan Hart5cbd2d72017-12-04 13:45:19 -0800101 }
102
Jonathan Hart7942fa02017-12-04 15:43:00 -0800103 stage ('Wait for release on Sonatype') {
Jonathan Hart5cbd2d72017-12-04 13:45:19 -0800104 timeout(time: 1, unit: 'HOURS') {
Jonathan Hart7942fa02017-12-04 15:43:00 -0800105 metadata = input id: 'release-build',
Jonathan Hart99ce7ff2018-05-30 14:46:00 -0700106 message: 'Go to http://oss.sonatype.org and release the artifacts',
107 submitter: userId
Jonathan Hart5cbd2d72017-12-04 13:45:19 -0800108 }
109 }
110
Jonathan Hart69938f52017-12-04 14:10:59 -0800111 stage ('Tag the release') {
Jonathan Hart5cbd2d72017-12-04 13:45:19 -0800112 sh 'git tag -a ' + version + ' -m "Tagging version ' + version + '"'
Jonathan Hart20225d82018-05-29 18:38:19 -0700113 sshagent (credentials: ['gerrit-jenkins-user']) {
114 sh 'git push origin ' + version
115 }
Jonathan Hart5cbd2d72017-12-04 13:45:19 -0800116 }
117
Jonathan Hart69938f52017-12-04 14:10:59 -0800118 stage ('Move to next SNAPSHOT version') {
Jonathan Hart5cbd2d72017-12-04 13:45:19 -0800119 def snapshot = nextVersion + '-SNAPSHOT'
120 changeVersion(snapshot)
121 sh 'git add -A && git commit -m "Starting snapshot ' + snapshot + '"'
Jonathan Hart20225d82018-05-29 18:38:19 -0700122 sshagent (credentials: ['gerrit-jenkins-user']) {
123 sh 'git push origin HEAD:refs/for/' + branch
124 }
Jonathan Hart5cbd2d72017-12-04 13:45:19 -0800125 }
126
Jonathan Hart69938f52017-12-04 14:10:59 -0800127 stage ('Finish') {
Jonathan Hart99ce7ff2018-05-30 14:46:00 -0700128 sh 'echo "Release done! Go to Gerrit and merge snapshot version bump"'
Jonathan Hart5cbd2d72017-12-04 13:45:19 -0800129 }
130
Jonathan Hart8d253832017-12-04 08:57:29 -0800131}
Jonathan Hartb9615f22018-05-30 10:56:01 -0700132