Carmelo Cascone | 9c00dce | 2019-12-05 18:33:04 -0800 | [diff] [blame] | 1 | // Copyright 2019-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. |
| 14 | |
Andrea Campanella | c638229 | 2021-03-26 13:17:43 +0100 | [diff] [blame] | 15 | def appRepo = '${appRepo}' |
| 16 | def appName = '${appName}' |
| 17 | def apiVersion = '${apiVersion}' |
| 18 | def nextApiVersion = '${nextApiVersion}' |
Carmelo Cascone | 9c00dce | 2019-12-05 18:33:04 -0800 | [diff] [blame] | 19 | def version = '${version}' |
| 20 | def nextVersion = '${nextVersion}' |
| 21 | def branch = '${branch}' |
| 22 | def jdkDistro = '${jdkDistro}' |
| 23 | |
| 24 | // This pipeline updates the <version> tag in the root pom.xml for the |
| 25 | // given app repo, and pushes two new Gerrit changes: |
| 26 | // 1) With version the given ${version} (e.g., 1.0.0) |
| 27 | // 2) With ${nextVersion}-SNAPSHOT (e.g., 1.1.0-SNAPSHOT) |
| 28 | // |
| 29 | // Users must manually approve and merge these changes on Gerrit. Once merged, |
| 30 | // it's up to the maven-publish and version-tag jobs to complete the release by |
| 31 | // uploading artifacts to Sonatype and creating Git tags. |
| 32 | |
| 33 | def changeVersion(def newVersion) { |
| 34 | // Update the top-level <version> tag in the root pom.xml. |
| 35 | sh 'mvn versions:set -DnewVersion=' + newVersion + ' versions:commit' |
| 36 | } |
| 37 | |
Andrea Campanella | c638229 | 2021-03-26 13:17:43 +0100 | [diff] [blame] | 38 | def changeApiVersion(def appName, def newApiVersion) { |
| 39 | // Update the top-level <*appName*.api.version> tag in the root pom.xml. |
| 40 | sh 'mvn versions:set-property -Dproperty=' + appName + '.api.version -DnewVersion=' + newApiVersion + ' -DallowSnapshots=true versions:commit' |
| 41 | } |
| 42 | |
Carmelo Cascone | 9c00dce | 2019-12-05 18:33:04 -0800 | [diff] [blame] | 43 | // TODO: use the declarative pipeline syntax, like all other groovy files. |
| 44 | // This implementation is based on the legacy cord-onos-publisher/Jenkinsfile.release |
| 45 | node ('ubuntu16.04-basebuild-1c-2g') { |
| 46 | |
Andrea Campanella | c638229 | 2021-03-26 13:17:43 +0100 | [diff] [blame] | 47 | sh 'echo Releasing ' + appRepo + ' repository on ' + branch + ' branch' |
Andrea Campanella | 4077801 | 2021-03-29 11:36:16 +0200 | [diff] [blame^] | 48 | sh 'echo Releasing version ' + version + ' with API version ' + apiVersion + ' and starting ' + nextVersion + '-SNAPSHOT with API version ' + apiVersion + '-SNAPSHOT' |
Carmelo Cascone | 9c00dce | 2019-12-05 18:33:04 -0800 | [diff] [blame] | 49 | |
| 50 | // Set the JDK version |
| 51 | sh 'echo Using JDK distribution: ' + jdkDistro |
| 52 | sh 'sudo update-java-alternatives --set ' + jdkDistro |
| 53 | sh 'echo Java Version:' |
| 54 | sh 'java -version' |
| 55 | |
| 56 | def userId = wrap([$class: 'BuildUser']) { |
| 57 | return env.BUILD_USER_ID |
| 58 | } |
| 59 | |
| 60 | stage ('Configure system') { |
| 61 | echo "Job triggered by " + userId |
| 62 | // FIXME: supply Jenkins-owned known_hosts file via config_file_provider |
| 63 | // https://jenkins.io/doc/pipeline/steps/config-file-provider/ |
| 64 | sh 'ssh-keyscan -H -t rsa -p 29418 gerrit.opencord.org >> ~/.ssh/known_hosts' |
| 65 | |
| 66 | sh 'git config --global user.name "Jenkins"' |
Zack Williams | 7a7a318 | 2020-08-13 14:15:40 -0700 | [diff] [blame] | 67 | sh 'git config --global user.email "do-not-reply@opennetworking.org"' |
Carmelo Cascone | 9c00dce | 2019-12-05 18:33:04 -0800 | [diff] [blame] | 68 | |
| 69 | // GPG key used to sign maven artifacts |
| 70 | withCredentials([file(credentialsId: 'gpg-creds-maven', variable: 'GPUPG')]) { |
| 71 | sh 'tar -xvf $GPUPG -C ~' |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | stage ('Check out code') { |
| 76 | cleanWs() |
| 77 | |
| 78 | sshagent (credentials: ['gerrit-jenkins-user']) { |
Andrea Campanella | c638229 | 2021-03-26 13:17:43 +0100 | [diff] [blame] | 79 | git branch: branch, url: 'ssh://jenkins@gerrit.opencord.org:29418/' + appRepo, credentialsId: 'gerrit-jenkins-user' |
Carmelo Cascone | 9c00dce | 2019-12-05 18:33:04 -0800 | [diff] [blame] | 80 | |
| 81 | sh 'gitdir=$(git rev-parse --git-dir); scp -p -P 29418 jenkins@gerrit.opencord.org:hooks/commit-msg ${gitdir}/hooks/' |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | stage ('Move to release version') { |
Andrea Campanella | c638229 | 2021-03-26 13:17:43 +0100 | [diff] [blame] | 86 | //Splitting version and apiVersion and check if apiVersion different from empty then update API it. |
| 87 | //Allows to release apps that dont' have api.version (e.g. bng,pppoe,kafka) |
Andrea Campanella | 4077801 | 2021-03-29 11:36:16 +0200 | [diff] [blame^] | 88 | changeVersion(version) |
Andrea Campanella | c638229 | 2021-03-26 13:17:43 +0100 | [diff] [blame] | 89 | if (apiVersion != "") { |
| 90 | changeApiVersion(appName, apiVersion) |
| 91 | } |
| 92 | sh 'git add -A && git commit -m "Release app version ' + version + ' with API version ' + apiVersion + '"' |
Carmelo Cascone | 9c00dce | 2019-12-05 18:33:04 -0800 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | stage ('Verify code') { |
| 96 | def found = sh script:'egrep -R SNAPSHOT .', returnStatus:true |
| 97 | |
| 98 | if (found == 0) { |
| 99 | timeout(time: 1, unit: 'HOURS') { |
| 100 | metadata = input id: 'manual-verify', |
| 101 | message: 'Found references to SNAPSHOT in the code. Are you sure you want to release?', |
| 102 | submitter: userId |
| 103 | } |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | stage ('Push to Gerrit') { |
| 108 | sshagent (credentials: ['gerrit-jenkins-user']) { |
| 109 | sh 'git push origin HEAD:refs/for/' + branch |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | stage ('Move to next SNAPSHOT version') { |
| 114 | def snapshot = nextVersion + '-SNAPSHOT' |
Andrea Campanella | c638229 | 2021-03-26 13:17:43 +0100 | [diff] [blame] | 115 | def apiSnapshot = nextApiVersion + '-SNAPSHOT' |
Carmelo Cascone | 9c00dce | 2019-12-05 18:33:04 -0800 | [diff] [blame] | 116 | changeVersion(snapshot) |
Andrea Campanella | c638229 | 2021-03-26 13:17:43 +0100 | [diff] [blame] | 117 | if (apiVersion != "") { |
| 118 | changeApiVersion(appName, apiSnapshot) |
| 119 | } |
| 120 | sh 'git add -A && git commit -m "Starting snapshot ' + snapshot + ' with API version ' + apiSnapshot + '"' |
Carmelo Cascone | 9c00dce | 2019-12-05 18:33:04 -0800 | [diff] [blame] | 121 | sshagent (credentials: ['gerrit-jenkins-user']) { |
| 122 | sh 'git push origin HEAD:refs/for/' + branch |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | stage ('Finish') { |
| 127 | sh 'echo "Release done!"' |
| 128 | sh 'echo "Go to Gerrit and merge new changes"' |
| 129 | sh 'echo "Go to http://oss.sonatype.org and release the artifacts (after the maven-publish job completes)"' |
| 130 | } |
| 131 | } |
| 132 | |