Jonathan Hart | 93be2a0 | 2017-12-04 09:23:34 -0800 | [diff] [blame] | 1 | // 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 Hart | 8d25383 | 2017-12-04 08:57:29 -0800 | [diff] [blame] | 14 | |
Jonathan Hart | 7b395df | 2017-12-04 10:07:17 -0800 | [diff] [blame] | 15 | def app = '${app}' |
| 16 | def version = '${version}' |
Jonathan Hart | 5cbd2d7 | 2017-12-04 13:45:19 -0800 | [diff] [blame] | 17 | def nextVersion = '${nextVersion}' |
Jonathan Hart | 7b395df | 2017-12-04 10:07:17 -0800 | [diff] [blame] | 18 | def branch = '${branch}' |
Jonathan Hart | 8d25383 | 2017-12-04 08:57:29 -0800 | [diff] [blame] | 19 | |
Jonathan Hart | 8d25383 | 2017-12-04 08:57:29 -0800 | [diff] [blame] | 20 | |
Jonathan Hart | 2b56499 | 2017-12-04 14:07:25 -0800 | [diff] [blame] | 21 | def changeVersion(def newVersion) { |
Jonathan Hart | 5cbd2d7 | 2017-12-04 13:45:19 -0800 | [diff] [blame] | 22 | // TODO any other versions we need to account for? |
| 23 | sh 'mvn versions:set -DnewVersion=' + newVersion + ' versions:commit' |
| 24 | } |
| 25 | |
Jonathan Hart | 6c0cca0 | 2018-05-29 10:43:30 -0700 | [diff] [blame] | 26 | node ('ubuntu16.04-basebuild-1c-2g') { |
Jonathan Hart | 8d25383 | 2017-12-04 08:57:29 -0800 | [diff] [blame] | 27 | |
Jonathan Hart | 20225d8 | 2018-05-29 18:38:19 -0700 | [diff] [blame^] | 28 | stage ('Configure Git') { |
| 29 | 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 Hart | 145b511 | 2018-05-29 16:16:56 -0700 | [diff] [blame] | 33 | } |
| 34 | |
Jonathan Hart | 7942fa0 | 2017-12-04 15:43:00 -0800 | [diff] [blame] | 35 | stage ('Checkout code') { |
| 36 | cleanWs() |
Jonathan Hart | 20225d8 | 2018-05-29 18:38:19 -0700 | [diff] [blame^] | 37 | |
| 38 | sshagent (credentials: ['gerrit-jenkins-user']) { |
| 39 | git branch: branch, url: 'ssh://jenkins@gerrit.opencord.org:29418/' + app, credentialsId: 'gerrit-jenkins-user' |
Jonathan Hart | 7942fa0 | 2017-12-04 15:43:00 -0800 | [diff] [blame] | 40 | |
Jonathan Hart | 20225d8 | 2018-05-29 18:38:19 -0700 | [diff] [blame^] | 41 | sh 'gitdir=$(git rev-parse --git-dir); scp -p -P 29418 jenkins@gerrit.opencord.org:hooks/commit-msg ${gitdir}/hooks/' |
| 42 | } |
Jonathan Hart | 7b395df | 2017-12-04 10:07:17 -0800 | [diff] [blame] | 43 | } |
Jonathan Hart | 5cbd2d7 | 2017-12-04 13:45:19 -0800 | [diff] [blame] | 44 | |
Jonathan Hart | 7942fa0 | 2017-12-04 15:43:00 -0800 | [diff] [blame] | 45 | stage ('Move to release version') { |
Jonathan Hart | 5cbd2d7 | 2017-12-04 13:45:19 -0800 | [diff] [blame] | 46 | changeVersion(version) |
Jonathan Hart | 5cbd2d7 | 2017-12-04 13:45:19 -0800 | [diff] [blame] | 47 | sh 'git add -A && git commit -m "Release version ' + version + '"' |
| 48 | } |
Jonathan Hart | 20225d8 | 2018-05-29 18:38:19 -0700 | [diff] [blame^] | 49 | |
| 50 | stage ('Verify code') { |
| 51 | def found = sh script:'egrep -R SNAPSHOT .' returnStatus:true |
| 52 | if (found == 0) { |
| 53 | timeout(time: 1, unit: 'HOURS') { |
| 54 | metadata = input id: 'manual-verify', |
| 55 | message: 'Found references to SNAPSHOT in the code. Are you sure you want to release?', |
| 56 | submitter: 'jono,dbainbri' |
| 57 | } |
| 58 | } |
| 59 | } |
Jonathan Hart | 8d25383 | 2017-12-04 08:57:29 -0800 | [diff] [blame] | 60 | |
Jonathan Hart | 7942fa0 | 2017-12-04 15:43:00 -0800 | [diff] [blame] | 61 | // This step is basically to test that everything still builds once the version has |
| 62 | // been bumped up before we start pushing things publicly |
Jonathan Hart | 69938f5 | 2017-12-04 14:10:59 -0800 | [diff] [blame] | 63 | stage ('Build and Test') { |
Jonathan Hart | 5cbd2d7 | 2017-12-04 13:45:19 -0800 | [diff] [blame] | 64 | // TODO can we do this with clean .m2? |
| 65 | sh 'mvn clean install' |
Jonathan Hart | 7942fa0 | 2017-12-04 15:43:00 -0800 | [diff] [blame] | 66 | sh 'mvn javadoc:javadoc' |
Jonathan Hart | 5cbd2d7 | 2017-12-04 13:45:19 -0800 | [diff] [blame] | 67 | } |
| 68 | |
Jonathan Hart | 69938f5 | 2017-12-04 14:10:59 -0800 | [diff] [blame] | 69 | stage ('Push to Gerrit') { |
Jonathan Hart | 20225d8 | 2018-05-29 18:38:19 -0700 | [diff] [blame^] | 70 | sshagent (credentials: ['gerrit-jenkins-user']) { |
| 71 | sh 'git push origin HEAD:refs/for/' + branch |
| 72 | } |
Jonathan Hart | 5cbd2d7 | 2017-12-04 13:45:19 -0800 | [diff] [blame] | 73 | } |
Jonathan Hart | 8d25383 | 2017-12-04 08:57:29 -0800 | [diff] [blame] | 74 | |
Jonathan Hart | 69938f5 | 2017-12-04 14:10:59 -0800 | [diff] [blame] | 75 | stage ('Wait for merge') { |
Jonathan Hart | 5cbd2d7 | 2017-12-04 13:45:19 -0800 | [diff] [blame] | 76 | timeout(time: 1, unit: 'HOURS') { |
Jonathan Hart | 7942fa0 | 2017-12-04 15:43:00 -0800 | [diff] [blame] | 77 | metadata = input id: 'release-build', |
| 78 | message: 'Go to Gerrit and merge the release patch', |
Jonathan Hart | 8df1639 | 2018-01-12 10:09:37 -0800 | [diff] [blame] | 79 | submitter: 'jono,dbainbri' |
Jonathan Hart | 5cbd2d7 | 2017-12-04 13:45:19 -0800 | [diff] [blame] | 80 | } |
| 81 | } |
| 82 | |
Jonathan Hart | 69938f5 | 2017-12-04 14:10:59 -0800 | [diff] [blame] | 83 | stage ('Release to Maven Central') { |
Jonathan Hart | 6c0cca0 | 2018-05-29 10:43:30 -0700 | [diff] [blame] | 84 | configFileProvider([configFile(fileId: 'onoscord-apps', variable: 'MAVEN_SETTINGS')]) { |
| 85 | sh 'mvn -s $MAVEN_SETTINGS -Prelease clean deploy' |
| 86 | } |
Jonathan Hart | 5cbd2d7 | 2017-12-04 13:45:19 -0800 | [diff] [blame] | 87 | } |
| 88 | |
Jonathan Hart | 7942fa0 | 2017-12-04 15:43:00 -0800 | [diff] [blame] | 89 | stage ('Wait for release on Sonatype') { |
Jonathan Hart | 5cbd2d7 | 2017-12-04 13:45:19 -0800 | [diff] [blame] | 90 | timeout(time: 1, unit: 'HOURS') { |
Jonathan Hart | 7942fa0 | 2017-12-04 15:43:00 -0800 | [diff] [blame] | 91 | metadata = input id: 'release-build', |
| 92 | message: 'Go to Sonatype and release the artifacts', |
Jonathan Hart | 8df1639 | 2018-01-12 10:09:37 -0800 | [diff] [blame] | 93 | submitter: 'jono,dbainbri' |
Jonathan Hart | 5cbd2d7 | 2017-12-04 13:45:19 -0800 | [diff] [blame] | 94 | } |
| 95 | } |
| 96 | |
Jonathan Hart | 69938f5 | 2017-12-04 14:10:59 -0800 | [diff] [blame] | 97 | stage ('Tag the release') { |
Jonathan Hart | 5cbd2d7 | 2017-12-04 13:45:19 -0800 | [diff] [blame] | 98 | sh 'git tag -a ' + version + ' -m "Tagging version ' + version + '"' |
Jonathan Hart | 20225d8 | 2018-05-29 18:38:19 -0700 | [diff] [blame^] | 99 | sshagent (credentials: ['gerrit-jenkins-user']) { |
| 100 | sh 'git push origin ' + version |
| 101 | } |
Jonathan Hart | 5cbd2d7 | 2017-12-04 13:45:19 -0800 | [diff] [blame] | 102 | } |
| 103 | |
Jonathan Hart | 69938f5 | 2017-12-04 14:10:59 -0800 | [diff] [blame] | 104 | stage ('Move to next SNAPSHOT version') { |
Jonathan Hart | 5cbd2d7 | 2017-12-04 13:45:19 -0800 | [diff] [blame] | 105 | def snapshot = nextVersion + '-SNAPSHOT' |
| 106 | changeVersion(snapshot) |
| 107 | sh 'git add -A && git commit -m "Starting snapshot ' + snapshot + '"' |
Jonathan Hart | 20225d8 | 2018-05-29 18:38:19 -0700 | [diff] [blame^] | 108 | sshagent (credentials: ['gerrit-jenkins-user']) { |
| 109 | sh 'git push origin HEAD:refs/for/' + branch |
| 110 | } |
Jonathan Hart | 5cbd2d7 | 2017-12-04 13:45:19 -0800 | [diff] [blame] | 111 | } |
| 112 | |
Jonathan Hart | 69938f5 | 2017-12-04 14:10:59 -0800 | [diff] [blame] | 113 | stage ('Finish') { |
Jonathan Hart | 5cbd2d7 | 2017-12-04 13:45:19 -0800 | [diff] [blame] | 114 | sh 'echo "Released new app. Go to Gerrit and merge snapshot version bump"' |
| 115 | } |
| 116 | |
Jonathan Hart | 8d25383 | 2017-12-04 08:57:29 -0800 | [diff] [blame] | 117 | } |