blob: 5934ad1a8dc215bba4e8665cebaac3b0fccceed8 [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}'
Zack Williamsf173e4f2019-08-30 17:15:24 -070019def jdkDistro = '${jdkDistro}'
Jonathan Hart8d253832017-12-04 08:57:29 -080020
Jonathan Hart2b564992017-12-04 14:07:25 -080021def changeVersion(def newVersion) {
Jonathan Hart5cbd2d72017-12-04 13:45:19 -080022 // TODO any other versions we need to account for?
23 sh 'mvn versions:set -DnewVersion=' + newVersion + ' versions:commit'
24}
25
Jonathan Hart6c0cca02018-05-29 10:43:30 -070026node ('ubuntu16.04-basebuild-1c-2g') {
Zack Williamsf173e4f2019-08-30 17:15:24 -070027
Jonathan Hart99ce7ff2018-05-30 14:46:00 -070028 sh 'echo Releasing ' + app + ' repository on ' + branch + ' branch'
29 sh 'echo Releasing version ' + version + ' and starting ' + nextVersion + '-SNAPSHOT'
Zack Williamsf173e4f2019-08-30 17:15:24 -070030
31 // Set the JDK version
32 sh 'echo Using JDK distribution: ' + jdkDistro
33 sh 'sudo update-java-alternatives --set ' +jdkDistro
34 sh 'echo Java Version:'
35 sh 'java -version'
36
Jonathan Hart99ce7ff2018-05-30 14:46:00 -070037 def userId = wrap([$class: 'BuildUser']) {
38 return env.BUILD_USER_ID
39 }
Jonathan Hart8d253832017-12-04 08:57:29 -080040
Jonathan Hartb9615f22018-05-30 10:56:01 -070041 stage ('Configure system') {
Jonathan Hart99ce7ff2018-05-30 14:46:00 -070042 echo "Release build triggered by " + userId
Zack Williamsf173e4f2019-08-30 17:15:24 -070043
Jonathan Hart20225d82018-05-29 18:38:19 -070044 sh 'ssh-keyscan -H -t rsa -p 29418 gerrit.opencord.org >> ~/.ssh/known_hosts'
Zack Williamsf173e4f2019-08-30 17:15:24 -070045
Jonathan Hart20225d82018-05-29 18:38:19 -070046 sh 'git config --global user.name "Jenkins"'
47 sh 'git config --global user.email "do-not-reply@opencord.org"'
Zack Williamsf173e4f2019-08-30 17:15:24 -070048
Jonathan Hart99ce7ff2018-05-30 14:46:00 -070049 // GPG key used to sign maven artifacts
Jonathan Hartb9615f22018-05-30 10:56:01 -070050 withCredentials([file(credentialsId: 'gpg-creds-maven', variable: 'GPUPG')]) {
51 sh 'tar -xvf $GPUPG -C ~'
52 }
Jonathan Hart145b5112018-05-29 16:16:56 -070053 }
54
Jonathan Hartb9615f22018-05-30 10:56:01 -070055 stage ('Check out code') {
Jonathan Hart7942fa02017-12-04 15:43:00 -080056 cleanWs()
Zack Williamsf173e4f2019-08-30 17:15:24 -070057
Jonathan Hart20225d82018-05-29 18:38:19 -070058 sshagent (credentials: ['gerrit-jenkins-user']) {
59 git branch: branch, url: 'ssh://jenkins@gerrit.opencord.org:29418/' + app, credentialsId: 'gerrit-jenkins-user'
Jonathan Hart7942fa02017-12-04 15:43:00 -080060
Jonathan Hart20225d82018-05-29 18:38:19 -070061 sh 'gitdir=$(git rev-parse --git-dir); scp -p -P 29418 jenkins@gerrit.opencord.org:hooks/commit-msg ${gitdir}/hooks/'
62 }
Jonathan Hart7b395df2017-12-04 10:07:17 -080063 }
Zack Williamsf173e4f2019-08-30 17:15:24 -070064
Jonathan Hart7942fa02017-12-04 15:43:00 -080065 stage ('Move to release version') {
Jonathan Hart5cbd2d72017-12-04 13:45:19 -080066 changeVersion(version)
Jonathan Hart5cbd2d72017-12-04 13:45:19 -080067 sh 'git add -A && git commit -m "Release version ' + version + '"'
68 }
Zack Williamsf173e4f2019-08-30 17:15:24 -070069
Jonathan Hart20225d82018-05-29 18:38:19 -070070 stage ('Verify code') {
Jonathan Hart55bef2c2018-05-29 18:40:37 -070071 def found = sh script:'egrep -R SNAPSHOT .', returnStatus:true
Zack Williamsf173e4f2019-08-30 17:15:24 -070072
Jonathan Hart20225d82018-05-29 18:38:19 -070073 if (found == 0) {
74 timeout(time: 1, unit: 'HOURS') {
Zack Williamsf173e4f2019-08-30 17:15:24 -070075 metadata = input id: 'manual-verify',
Jonathan Hart20225d82018-05-29 18:38:19 -070076 message: 'Found references to SNAPSHOT in the code. Are you sure you want to release?',
Jonathan Hart99ce7ff2018-05-30 14:46:00 -070077 submitter: userId
Jonathan Hart20225d82018-05-29 18:38:19 -070078 }
79 }
80 }
Zack Williamsf173e4f2019-08-30 17:15:24 -070081
Jonathan Hart7942fa02017-12-04 15:43:00 -080082 // This step is basically to test that everything still builds once the version has
83 // been bumped up before we start pushing things publicly
Jonathan Hart69938f52017-12-04 14:10:59 -080084 stage ('Build and Test') {
Jonathan Hart5cbd2d72017-12-04 13:45:19 -080085 sh 'mvn clean install'
Jonathan Hart7942fa02017-12-04 15:43:00 -080086 sh 'mvn javadoc:javadoc'
Jonathan Hart5cbd2d72017-12-04 13:45:19 -080087 }
88
Jonathan Hart69938f52017-12-04 14:10:59 -080089 stage ('Push to Gerrit') {
Jonathan Hart20225d82018-05-29 18:38:19 -070090 sshagent (credentials: ['gerrit-jenkins-user']) {
91 sh 'git push origin HEAD:refs/for/' + branch
92 }
Jonathan Hart5cbd2d72017-12-04 13:45:19 -080093 }
Zack Williamsf173e4f2019-08-30 17:15:24 -070094
Jonathan Hart69938f52017-12-04 14:10:59 -080095 stage ('Wait for merge') {
Jonathan Harta85af1e2018-05-30 11:54:47 -070096 timeout(time: 1, unit: 'HOURS') {
Zack Williamsf173e4f2019-08-30 17:15:24 -070097 metadata = input id: 'release-build',
Jonathan Harta85af1e2018-05-30 11:54:47 -070098 message: 'Go to Gerrit and merge the release patch',
Jonathan Hart99ce7ff2018-05-30 14:46:00 -070099 submitter: userId
Jonathan Hart5cbd2d72017-12-04 13:45:19 -0800100 }
Zack Williamsf173e4f2019-08-30 17:15:24 -0700101
Jonathan Hart5cbd2d72017-12-04 13:45:19 -0800102 }
103
Jonathan Hart99ce7ff2018-05-30 14:46:00 -0700104 stage ('Release artifacts') {
Jonathan Hart6c0cca02018-05-29 10:43:30 -0700105 configFileProvider([configFile(fileId: 'onoscord-apps', variable: 'MAVEN_SETTINGS')]) {
106 sh 'mvn -s $MAVEN_SETTINGS -Prelease clean deploy'
107 }
Jonathan Hart5cbd2d72017-12-04 13:45:19 -0800108 }
109
Jonathan Hart7942fa02017-12-04 15:43:00 -0800110 stage ('Wait for release on Sonatype') {
Jonathan Hart5cbd2d72017-12-04 13:45:19 -0800111 timeout(time: 1, unit: 'HOURS') {
Zack Williamsf173e4f2019-08-30 17:15:24 -0700112 metadata = input id: 'release-build',
Jonathan Hart99ce7ff2018-05-30 14:46:00 -0700113 message: 'Go to http://oss.sonatype.org and release the artifacts',
114 submitter: userId
Jonathan Hart5cbd2d72017-12-04 13:45:19 -0800115 }
116 }
117
Jonathan Hart69938f52017-12-04 14:10:59 -0800118 stage ('Tag the release') {
Jonathan Hart5cbd2d72017-12-04 13:45:19 -0800119 sh 'git tag -a ' + version + ' -m "Tagging version ' + version + '"'
Jonathan Hart20225d82018-05-29 18:38:19 -0700120 sshagent (credentials: ['gerrit-jenkins-user']) {
121 sh 'git push origin ' + version
122 }
Jonathan Hart5cbd2d72017-12-04 13:45:19 -0800123 }
Zack Williamsf173e4f2019-08-30 17:15:24 -0700124
Jonathan Hart69938f52017-12-04 14:10:59 -0800125 stage ('Move to next SNAPSHOT version') {
Jonathan Hart5cbd2d72017-12-04 13:45:19 -0800126 def snapshot = nextVersion + '-SNAPSHOT'
127 changeVersion(snapshot)
128 sh 'git add -A && git commit -m "Starting snapshot ' + snapshot + '"'
Jonathan Hart20225d82018-05-29 18:38:19 -0700129 sshagent (credentials: ['gerrit-jenkins-user']) {
130 sh 'git push origin HEAD:refs/for/' + branch
131 }
Jonathan Hart5cbd2d72017-12-04 13:45:19 -0800132 }
133
Jonathan Hart69938f52017-12-04 14:10:59 -0800134 stage ('Finish') {
Jonathan Hart99ce7ff2018-05-30 14:46:00 -0700135 sh 'echo "Release done! Go to Gerrit and merge snapshot version bump"'
Jonathan Hart5cbd2d72017-12-04 13:45:19 -0800136 }
Zack Williamsf173e4f2019-08-30 17:15:24 -0700137
Jonathan Hart8d253832017-12-04 08:57:29 -0800138}
Jonathan Hartb9615f22018-05-30 10:56:01 -0700139