Skip to content

Commit 3d4597b

Browse files
committed
Release Jenkinsfile: add a configurable constant to enable/disable release on push
1 parent 66c5bd5 commit 3d4597b

File tree

1 file changed

+30
-18
lines changed

1 file changed

+30
-18
lines changed

ci/release/Jenkinsfile

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@
1313

1414
import org.hibernate.jenkins.pipeline.helpers.version.Version
1515

16-
def checkoutReleaseScripts() {
17-
dir('.release/scripts') {
18-
checkout scmGit(branches: [[name: '*/main']], extensions: [],
19-
userRemoteConfigs: [[credentialsId: 'ed25519.Hibernate-CI.github.com',
20-
url: 'https://github.com/hibernate/hibernate-release-scripts.git']])
21-
}
22-
}
16+
// --------------------------------------------
17+
// Global build configuration
18+
env.PROJECT = "orm"
19+
env.JIRA_KEY = "HHH"
20+
def RELEASE_ON_PUSH = false // Set to `true` *only* on branches where you want a release on each push.
21+
22+
// --------------------------------------------
23+
// Build conditions
2324

2425
// Avoid running the pipeline on branch indexing
2526
if (currentBuild.getBuildCauses().toString().contains('BranchIndexingCause')) {
@@ -28,8 +29,28 @@ if (currentBuild.getBuildCauses().toString().contains('BranchIndexingCause')) {
2829
return
2930
}
3031

31-
env.PROJECT = "orm"
32-
env.JIRA_KEY = "HHH"
32+
def manualRelease = currentBuild.getBuildCauses().toString().contains( 'UserIdCause' )
33+
34+
// Only do automatic release on branches where we opted in
35+
if ( !manualRelease && !RELEASE_ON_PUSH ) {
36+
print "INFO: Build skipped because automated releases are disabled on this branch. See constant RELEASE_ON_PUSH in ci/release/Jenkinsfile"
37+
currentBuild.result = 'NOT_BUILT'
38+
return
39+
}
40+
41+
// --------------------------------------------
42+
// Reusable methods
43+
44+
def checkoutReleaseScripts() {
45+
dir('.release/scripts') {
46+
checkout scmGit(branches: [[name: '*/main']], extensions: [],
47+
userRemoteConfigs: [[credentialsId: 'ed25519.Hibernate-CI.github.com',
48+
url: 'https://github.com/hibernate/hibernate-release-scripts.git']])
49+
}
50+
}
51+
52+
// --------------------------------------------
53+
// Pipeline
3354

3455
pipeline {
3556
agent {
@@ -69,8 +90,6 @@ pipeline {
6990
script {
7091
checkoutReleaseScripts()
7192

72-
def manualRelease = currentBuild.getBuildCauses().toString().contains( 'UserIdCause' )
73-
7493
def currentVersion = Version.parseDevelopmentVersion( sh(
7594
script: ".release/scripts/determine-current-version.sh ${env.PROJECT}",
7695
returnStdout: true
@@ -95,13 +114,6 @@ pipeline {
95114
else {
96115
echo "Release was triggered automatically"
97116

98-
// Avoid doing an automatic release on a non-maintenance branch
99-
if ( ! ( env.BRANCH_NAME ==~ /^\d+\.\d+$/ ) ) {
100-
print "INFO: Automatic release skipped because the branch name doesn't follow pattern /^\\d+\\.\\d+\$/"
101-
currentBuild.result = 'ABORTED'
102-
return
103-
}
104-
105117
// Avoid doing an automatic release for commits from a release
106118
def lastCommitter = sh(script: 'git show -s --format=\'%an\'', returnStdout: true)
107119
def secondLastCommitter = sh(script: 'git show -s --format=\'%an\' HEAD~1', returnStdout: true)

0 commit comments

Comments
 (0)