blob: 7616a8853b6f8e394c62b8515bd2b9aaa3cc2c93 [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 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') {
Jonathan Hart8d253832017-12-04 08:57:29 -080027
Jonathan Hartb9615f22018-05-30 10:56:01 -070028 stage ('Configure system') {
Jonathan Hart20225d82018-05-29 18:38:19 -070029 sh 'ssh-keyscan -H -t rsa -p 29418 gerrit.opencord.org >> ~/.ssh/known_hosts'
30
31 sh 'git config --global user.name "Jenkins"'
32 sh 'git config --global user.email "do-not-reply@opencord.org"'
Jonathan Hartb9615f22018-05-30 10:56:01 -070033
34 withCredentials([file(credentialsId: 'gpg-creds-maven', variable: 'GPUPG')]) {
35 sh 'tar -xvf $GPUPG -C ~'
36 }
Jonathan Hart145b5112018-05-29 16:16:56 -070037 }
38
Jonathan Hartb9615f22018-05-30 10:56:01 -070039 stage ('Check out code') {
Jonathan Hart7942fa02017-12-04 15:43:00 -080040 cleanWs()
Jonathan Hart20225d82018-05-29 18:38:19 -070041
42 sshagent (credentials: ['gerrit-jenkins-user']) {
43 git branch: branch, url: 'ssh://jenkins@gerrit.opencord.org:29418/' + app, credentialsId: 'gerrit-jenkins-user'
Jonathan Hart7942fa02017-12-04 15:43:00 -080044
Jonathan Hart20225d82018-05-29 18:38:19 -070045 sh 'gitdir=$(git rev-parse --git-dir); scp -p -P 29418 jenkins@gerrit.opencord.org:hooks/commit-msg ${gitdir}/hooks/'
46 }
Jonathan Hart7b395df2017-12-04 10:07:17 -080047 }
Jonathan Hart5cbd2d72017-12-04 13:45:19 -080048
Jonathan Hart7942fa02017-12-04 15:43:00 -080049 stage ('Move to release version') {
Jonathan Hart5cbd2d72017-12-04 13:45:19 -080050 changeVersion(version)
Jonathan Hart5cbd2d72017-12-04 13:45:19 -080051 sh 'git add -A && git commit -m "Release version ' + version + '"'
52 }
Jonathan Hartb9615f22018-05-30 10:56:01 -070053
Jonathan Hart20225d82018-05-29 18:38:19 -070054 stage ('Verify code') {
Jonathan Hart55bef2c2018-05-29 18:40:37 -070055 def found = sh script:'egrep -R SNAPSHOT .', returnStatus:true
Jonathan Hartb9615f22018-05-30 10:56:01 -070056
Jonathan Hart20225d82018-05-29 18:38:19 -070057 if (found == 0) {
58 timeout(time: 1, unit: 'HOURS') {
59 metadata = input id: 'manual-verify',
60 message: 'Found references to SNAPSHOT in the code. Are you sure you want to release?',
61 submitter: 'jono,dbainbri'
62 }
63 }
64 }
Jonathan Hart8d253832017-12-04 08:57:29 -080065
Jonathan Hart7942fa02017-12-04 15:43:00 -080066 // This step is basically to test that everything still builds once the version has
67 // been bumped up before we start pushing things publicly
Jonathan Hart69938f52017-12-04 14:10:59 -080068 stage ('Build and Test') {
Jonathan Hart5cbd2d72017-12-04 13:45:19 -080069 // TODO can we do this with clean .m2?
70 sh 'mvn clean install'
Jonathan Hart7942fa02017-12-04 15:43:00 -080071 sh 'mvn javadoc:javadoc'
Jonathan Hart5cbd2d72017-12-04 13:45:19 -080072 }
73
Jonathan Hart69938f52017-12-04 14:10:59 -080074 stage ('Push to Gerrit') {
Jonathan Hart20225d82018-05-29 18:38:19 -070075 sshagent (credentials: ['gerrit-jenkins-user']) {
76 sh 'git push origin HEAD:refs/for/' + branch
77 }
Jonathan Hart5cbd2d72017-12-04 13:45:19 -080078 }
Jonathan Hart8d253832017-12-04 08:57:29 -080079
Jonathan Hart69938f52017-12-04 14:10:59 -080080 stage ('Wait for merge') {
Jonathan Harta85af1e2018-05-30 11:54:47 -070081 timeout(time: 1, unit: 'HOURS') {
82 metadata = input id: 'release-build',
83 message: 'Go to Gerrit and merge the release patch',
84 submitter: 'jono,dbainbri'
Jonathan Hart5cbd2d72017-12-04 13:45:19 -080085 }
86 }
87
Jonathan Hart69938f52017-12-04 14:10:59 -080088 stage ('Release to Maven Central') {
Jonathan Hart6c0cca02018-05-29 10:43:30 -070089 configFileProvider([configFile(fileId: 'onoscord-apps', variable: 'MAVEN_SETTINGS')]) {
90 sh 'mvn -s $MAVEN_SETTINGS -Prelease clean deploy'
91 }
Jonathan Hart5cbd2d72017-12-04 13:45:19 -080092 }
93
Jonathan Hart7942fa02017-12-04 15:43:00 -080094 stage ('Wait for release on Sonatype') {
Jonathan Hart5cbd2d72017-12-04 13:45:19 -080095 timeout(time: 1, unit: 'HOURS') {
Jonathan Hart7942fa02017-12-04 15:43:00 -080096 metadata = input id: 'release-build',
97 message: 'Go to Sonatype and release the artifacts',
Jonathan Hart8df16392018-01-12 10:09:37 -080098 submitter: 'jono,dbainbri'
Jonathan Hart5cbd2d72017-12-04 13:45:19 -080099 }
100 }
101
Jonathan Hart69938f52017-12-04 14:10:59 -0800102 stage ('Tag the release') {
Jonathan Hart5cbd2d72017-12-04 13:45:19 -0800103 sh 'git tag -a ' + version + ' -m "Tagging version ' + version + '"'
Jonathan Hart20225d82018-05-29 18:38:19 -0700104 sshagent (credentials: ['gerrit-jenkins-user']) {
105 sh 'git push origin ' + version
106 }
Jonathan Hart5cbd2d72017-12-04 13:45:19 -0800107 }
108
Jonathan Hart69938f52017-12-04 14:10:59 -0800109 stage ('Move to next SNAPSHOT version') {
Jonathan Hart5cbd2d72017-12-04 13:45:19 -0800110 def snapshot = nextVersion + '-SNAPSHOT'
111 changeVersion(snapshot)
112 sh 'git add -A && git commit -m "Starting snapshot ' + snapshot + '"'
Jonathan Hart20225d82018-05-29 18:38:19 -0700113 sshagent (credentials: ['gerrit-jenkins-user']) {
114 sh 'git push origin HEAD:refs/for/' + branch
115 }
Jonathan Hart5cbd2d72017-12-04 13:45:19 -0800116 }
117
Jonathan Hart69938f52017-12-04 14:10:59 -0800118 stage ('Finish') {
Jonathan Hart5cbd2d72017-12-04 13:45:19 -0800119 sh 'echo "Released new app. Go to Gerrit and merge snapshot version bump"'
120 }
121
Jonathan Hart8d253832017-12-04 08:57:29 -0800122}
Jonathan Hartb9615f22018-05-30 10:56:01 -0700123