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