Adjust for hotfix releases

This commit is contained in:
René Pfeuffer
2022-01-18 09:24:26 +01:00
parent 1021640a4c
commit 913d3dbf59

55
Jenkinsfile vendored
View File

@@ -23,7 +23,10 @@ pipeline {
stage('Set Version') { stage('Set Version') {
when { when {
branch pattern: 'release/*', comparator: 'GLOB' anyOf {
branch pattern: 'release/*', comparator: 'GLOB'
branch pattern: 'hotfix/*', comparator: 'GLOB'
}
} }
steps { steps {
// read version from branch, set it and commit it // read version from branch, set it and commit it
@@ -35,10 +38,13 @@ pipeline {
sh 'git config --replace-all "remote.origin.fetch" "+refs/heads/*:refs/remotes/origin/*"' sh 'git config --replace-all "remote.origin.fetch" "+refs/heads/*:refs/remotes/origin/*"'
sh 'git fetch --all' sh 'git fetch --all'
// checkout, reset and merge script {
sh 'git checkout master' if (isReleaseBuild()) {
sh 'git reset --hard origin/master' // checkout, reset and merge
sh "git merge --ff-only ${env.BRANCH_NAME}" sh 'git reset --hard origin/master'
sh "git merge --ff-only ${env.BRANCH_NAME}"
}
}
// set tag // set tag
tag releaseVersion tag releaseVersion
@@ -101,6 +107,7 @@ pipeline {
when { when {
anyOf { anyOf {
branch pattern: 'release/*', comparator: 'GLOB' branch pattern: 'release/*', comparator: 'GLOB'
branch pattern: 'hotfix/*', comparator: 'GLOB'
branch 'develop' branch 'develop'
} }
expression { return isBuildSuccess() } expression { return isBuildSuccess() }
@@ -131,16 +138,20 @@ pipeline {
stage('Push Tag') { stage('Push Tag') {
when { when {
branch pattern: 'release/*', comparator: 'GLOB' branch pattern: 'release/*', comparator: 'GLOB'
branch pattern: 'hotfix/*', comparator: 'GLOB'
expression { return isBuildSuccess() } expression { return isBuildSuccess() }
} }
steps { steps {
// push changes back to remote repository script {
authGit 'cesmarvin-github', 'push origin master --tags' // push changes back to remote repository
authGit 'cesmarvin-github', 'push origin --tags' if (isReleaseBuild()) {
authGit 'cesmarvin-github', 'push origin master --tags'
}
authGit 'cesmarvin-github', 'push origin --tags'
}
} }
} }
stage('Set Next Version') { stage('Set Next Version') {
when { when {
branch pattern: 'release/*', comparator: 'GLOB' branch pattern: 'release/*', comparator: 'GLOB'
@@ -169,6 +180,20 @@ pipeline {
} }
} }
stage('Send Merge Notification') {
when {
branch pattern: 'hotfix/*', comparator: 'GLOB'
expression { return isBuildSuccess() }
}
steps {
mail to: "scm-team@cloudogu.com",
subject: "Jenkins Job ${JOB_NAME} - Merge Hotfix Release #${env.BRANCH_NAME}!",
body: """Please,
- merge the hotfix release branch ${env.BRANCH_NAME} into master (keep versions of master, merge changelog to keep both versions),
- merge master into develop (the changelog should have no conflicts),
- if needed, increase version."""
}
}
} }
post { post {
@@ -195,8 +220,16 @@ void gradle(String command) {
sh "./gradlew -Duser.home=${env.WORKSPACE} ${command}" sh "./gradlew -Duser.home=${env.WORKSPACE} ${command}"
} }
boolean isReleaseBuild() {
return env.BRANCH_NAME.startsWith('release/')
}
String getReleaseVersion() { String getReleaseVersion() {
return env.BRANCH_NAME.substring("release/".length()); if (isReleaseBuild()) {
return env.BRANCH_NAME.substring("release/".length());
} else {
return env.BRANCH_NAME.substring("hotfix/".length());
}
} }
void commit(String message) { void commit(String message) {
@@ -208,7 +241,7 @@ void tag(String version) {
sh "git -c user.name='CES Marvin' -c user.email='cesmarvin@cloudogu.com' tag -m '${message}' ${version}" sh "git -c user.name='CES Marvin' -c user.email='cesmarvin@cloudogu.com' tag -m '${message}' ${version}"
} }
void isBuildSuccess() { boolean isBuildSuccess() {
return currentBuild.result == null || currentBuild.result == 'SUCCESS' return currentBuild.result == null || currentBuild.result == 'SUCCESS'
} }