blob: 0e26b02c831303e79c0847294a9d6214bcaba5cd [file] [log] [blame]
// Copyright 2017-present Open Networking Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
def app = '${app}'
def version = '${version}'
def nextVersion = '${nextVersion}'
def branch = '${branch}'
def createBranch(def proj, def branch, def parent) {
cmd = 'ssh -p 29418 gerrit.opencord.org gerrit create-branch ' + proj + " " + branch + " " + parent
sh returnStdout: true, script: cmd
}
int checkBranchExists(def proj, def branch) {
url = 'https://gerrit.opencord.org/projects/' + proj + '/branches/' + branch
response = httpRequest url: url, validResponseCodes: '200,404'
if (response.status == 404) {
return 1
}
return 0
}
def changeVersion(dev newVersion) {
// TODO any other versions we need to account for?
sh 'mvn versions:set -DnewVersion=' + newVersion + ' versions:commit'
}
node ('master') {
stage 'Checkout code' {
//checkout([$class: 'RepoScm', currentBranch: true, manifestRepositoryUrl: 'https://gerrit.opencord.org/manifest', quiet: true])
git branch: branch, url: 'ssh://jenkins@gerrit.opencord.org:29418/' + app
}
//stage 'Create support branch'
//if (checkBranchExists(app, branch) == 0) {
// echo "Branch " + branch + " doesn't exist, creating
//createBranch(app, version, 'opencord/master')
//} else {
// echo "Support branch " + branch + " already exists"
//}
stage 'Checkout branch' {
sh 'git checkout ' + branch
sh 'gitdir=$(git rev-parse --git-dir); scp -p -P 29418 jenkins@gerrit.opencord.org:hooks/commit-msg ${gitdir}/hooks/'
}
stage 'Bump versions' {
changeVersion(version)
}
stage 'Commit' {
sh 'git add -A && git commit -m "Release version ' + version + '"'
}
stage 'Build and Test' {
// TODO can we do this with clean .m2?
sh 'mvn clean install'
}
stage 'Push to Gerrit' {
sh 'git push origin HEAD:refs/for/' + branch
}
stage 'Wait for merge' {
timeout(time: 1, unit: 'HOURS') {
metadata = input id: 'release-build', message: 'Go to Gerrit and merge the release patch',
submitter: 'jono'
}
}
stage 'Release to Maven Central' {
sh 'mvn -Prelease clean deploy'
}
stage 'Wait for release OKed' {
timeout(time: 1, unit: 'HOURS') {
metadata = input id: 'release-build', message: 'Release the artifacts on Sonatype',
submitter: 'jono'
}
}
stage 'Tag the release' {
sh 'git tag -a ' + version + ' -m "Tagging version ' + version + '"'
sh 'git push origin ' + version
}
stage 'Move to next SNAPSHOT version' {
def snapshot = nextVersion + '-SNAPSHOT'
changeVersion(snapshot)
sh 'git add -A && git commit -m "Starting snapshot ' + snapshot + '"'
sh 'git push origin HEAD:refs/for/' + branch
}
stage 'Finish' {
sh 'echo "Released new app. Go to Gerrit and merge snapshot version bump"'
}
}