11
11
*/
12
12
13
13
14
+ import org.hibernate.jenkins.pipeline.helpers.version.Version
15
+
16
+ // --------------------------------------------
17
+ // Global build configuration
18
+ env. PROJECT = " orm"
19
+ env. JIRA_KEY = " HHH"
20
+ def RELEASE_ON_SCHEDULE = true // Set to `true` *only* on branches where you want a scheduled release.
21
+
22
+ print " INFO: env.PROJECT = ${ env.PROJECT} "
23
+ print " INFO: env.JIRA_KEY = ${ env.JIRA_KEY} "
24
+
25
+ // --------------------------------------------
26
+ // Build conditions
27
+
14
28
// Avoid running the pipeline on branch indexing
15
29
if (currentBuild. getBuildCauses(). toString(). contains(' BranchIndexingCause' )) {
16
30
print " INFO: Build skipped due to trigger being Branch Indexing"
17
31
currentBuild. result = ' NOT_BUILT'
18
32
return
19
33
}
20
34
21
- env. PROJECT = " orm"
22
- env. JIRA_KEY = " HHH"
35
+ def manualRelease = currentBuild. getBuildCauses(). toString(). contains( ' UserIdCause' )
36
+ def cronRelease = currentBuild. getBuildCauses(). toString(). contains( ' TimerTriggerCause' )
37
+
38
+ // Only do automatic release on branches where we opted in
39
+ if ( ! manualRelease && ! cronRelease ) {
40
+ print " INFO: Build skipped because automated releases on push are disabled on this branch."
41
+ currentBuild. result = ' NOT_BUILT'
42
+ return
43
+ }
44
+
45
+ if ( ! manualRelease && cronRelease && ! RELEASE_ON_SCHEDULE ) {
46
+ print " INFO: Build skipped because automated releases are disabled on this branch. See constant RELEASE_ON_SCHEDULE in ci/release/Jenkinsfile"
47
+ currentBuild. result = ' NOT_BUILT'
48
+ return
49
+ }
50
+
51
+ // --------------------------------------------
52
+ // Reusable methods
53
+
54
+ def checkoutReleaseScripts () {
55
+ dir(' .release/scripts' ) {
56
+ checkout scmGit(branches : [[name : ' */main' ]], extensions : [],
57
+ userRemoteConfigs : [[credentialsId : ' ed25519.Hibernate-CI.github.com' ,
58
+ url : ' https://github.com/hibernate/hibernate-release-scripts.git' ]])
59
+ }
60
+ }
61
+
62
+ // --------------------------------------------
63
+ // Pipeline
23
64
24
65
pipeline {
25
66
agent {
26
67
label ' Worker&&Containers'
27
68
}
69
+ triggers {
70
+ // Run every week Sunday midnight
71
+ cron(' 0 0 * * 0' )
72
+ }
28
73
tools {
29
74
jdk ' OpenJDK 11 Latest'
30
75
}
31
76
options {
32
77
buildDiscarder logRotator(daysToKeepStr : ' 30' , numToKeepStr : ' 10' )
33
- rateLimitBuilds(throttle : [count : 1 , durationName : ' day' , userBoost : true ])
34
78
disableConcurrentBuilds(abortPrevious : false )
35
79
preserveStashes()
36
80
}
37
81
parameters {
38
82
string(
39
83
name : ' RELEASE_VERSION' ,
40
84
defaultValue : ' ' ,
41
- description : ' The version to be released, e.g. 6.2.1.Final.' ,
85
+ description : ' The version to be released, e.g. 6.2.1.Final. Mandatory for manual releases, to prevent mistakes. ' ,
42
86
trim : true
43
87
)
44
88
string(
45
89
name : ' DEVELOPMENT_VERSION' ,
46
90
defaultValue : ' ' ,
47
- description : ' The next version to be used after the release, e.g. 6.2.2-SNAPSHOT.' ,
91
+ description : ' The next version to be used after the release, e.g. 6.2.2-SNAPSHOT. If not set, determined automatically from the release version. ' ,
48
92
trim : true
49
93
)
50
94
booleanParam(
@@ -61,96 +105,107 @@ pipeline {
61
105
print " INFO: params.DEVELOPMENT_VERSION = ${ params.DEVELOPMENT_VERSION} "
62
106
print " INFO: params.RELEASE_DRY_RUN? = ${ params.RELEASE_DRY_RUN} "
63
107
64
- // Avoid doing a release for commits from a release
65
- def lastCommitter = sh(script : ' git show -s --format=\' %an\' ' , returnStdout : true ). trim()
66
- def secondLastCommitter = sh(script : ' git show -s --format=\' %an\' HEAD~1' , returnStdout : true ). trim()
67
- if (lastCommitter == ' Hibernate-CI' && secondLastCommitter == ' Hibernate-CI' ) {
68
- print " INFO: Release skipped because last commits were for the previous release"
69
- currentBuild. getRawBuild(). getExecutor(). interrupt(Result . NOT_BUILT )
70
- sleep(1 ) // Interrupt is not blocking and does not take effect immediately.
71
- return
72
- }
108
+ checkoutReleaseScripts()
73
109
74
- dir(' .release/scripts' ) {
75
- checkout scmGit(branches : [[name : ' */main' ]], extensions : [], userRemoteConfigs : [[credentialsId : ' ed25519.Hibernate-CI.github.com' , url : ' https://github.com/hibernate/hibernate-release-scripts.git' ]])
76
- }
77
- // Determine version information for release process
78
- env. CURRENT_VERSION = sh(
110
+ def currentVersion = Version . parseDevelopmentVersion( sh(
79
111
script : " .release/scripts/determine-current-version.sh ${ env.PROJECT} " ,
80
112
returnStdout : true
81
- ). trim()
113
+ ). trim() )
114
+ echo " Workspace version: ${ currentVersion} "
82
115
83
- if ( params. RELEASE_VERSION == null || params. RELEASE_VERSION . isEmpty() ) {
84
- env. RELEASE_VERSION = sh(
85
- script : " .release/scripts/determine-release-version.sh ${ env.CURRENT_VERSION} " ,
86
- returnStdout : true
87
- ). trim()
116
+ def releaseVersion
117
+ def developmentVersion
118
+
119
+ if ( manualRelease ) {
120
+ echo " Release was requested manually"
121
+
122
+ if ( ! params. RELEASE_VERSION ) {
123
+ throw new IllegalArgumentException (
124
+ ' Missing value for parameter RELEASE_VERSION. This parameter must be set explicitly to prevent mistakes.'
125
+ )
126
+ }
127
+ releaseVersion = Version . parseReleaseVersion( params. RELEASE_VERSION )
128
+
129
+ if ( ! releaseVersion. toString(). startsWith( currentVersion. family + ' .' ) ) {
130
+ throw new IllegalArgumentException ( " RELEASE_VERSION = $releaseVersion , which is different from the family of CURRENT_VERSION = $currentVersion . Did you make a mistake?" )
131
+ }
88
132
}
89
133
else {
90
- env. RELEASE_VERSION = params. RELEASE_VERSION
134
+ echo " Release was triggered automatically"
135
+
136
+ // Avoid doing an automatic release for commits from a release
137
+ def lastCommitter = sh(script : ' git show -s --format=\' %an\' ' , returnStdout : true )
138
+ def secondLastCommitter = sh(script : ' git show -s --format=\' %an\' HEAD~1' , returnStdout : true )
139
+ if (lastCommitter == ' Hibernate-CI' && secondLastCommitter == ' Hibernate-CI' ) {
140
+ print " INFO: Automatic release skipped because last commits were for the previous release"
141
+ currentBuild. getRawBuild(). getExecutor(). interrupt(Result . NOT_BUILT )
142
+ sleep(1 ) // Interrupt is not blocking and does not take effect immediately.
143
+ return
144
+ }
145
+
146
+ releaseVersion = Version . parseReleaseVersion( sh(
147
+ script : " .release/scripts/determine-release-version.sh ${ currentVersion} " ,
148
+ returnStdout : true
149
+ ). trim() )
91
150
}
92
- if ( params. DEVELOPMENT_VERSION == null || params. DEVELOPMENT_VERSION . isEmpty() ) {
93
- env. DEVELOPMENT_VERSION = sh(
94
- script : " .release/scripts/determine-development-version.sh ${ env.RELEASE_VERSION} " ,
151
+ echo " Release version: ${ releaseVersion} "
152
+
153
+ if ( ! params. DEVELOPMENT_VERSION ) {
154
+ developmentVersion = Version . parseDevelopmentVersion( sh(
155
+ script : " .release/scripts/determine-development-version.sh ${ releaseVersion} " ,
95
156
returnStdout : true
96
- ). trim()
157
+ ). trim() )
97
158
}
98
159
else {
99
- env . DEVELOPMENT_VERSION = params. DEVELOPMENT_VERSION
160
+ developmentVersion = Version . parseDevelopmentVersion( params. DEVELOPMENT_VERSION )
100
161
}
101
- env. VERSION_BASIS = sh(
102
- script : " .release/scripts/determine-version-basis.sh ${ env.RELEASE_VERSION} " ,
103
- returnStdout : true
104
- ). trim()
105
- env. VERSION_FAMILY = sh(
106
- script : " .release/scripts/determine-version-family.sh ${ env.RELEASE_VERSION} " ,
107
- returnStdout : true
108
- ). trim()
109
- env. NEXT_VERSION_BASIS = sh(
110
- script : " .release/scripts/determine-version-basis.sh ${ env.DEVELOPMENT_VERSION} " ,
111
- returnStdout : true
112
- ). trim()
162
+ echo " Development version: ${ developmentVersion} "
163
+
164
+ env. RELEASE_VERSION = releaseVersion. toString()
165
+ env. DEVELOPMENT_VERSION = developmentVersion. toString()
113
166
env. SCRIPT_OPTIONS = params. RELEASE_DRY_RUN ? " -d" : " "
114
- echo " Workspace version: ${ env.CURRENT_VERSION} "
115
- echo " Release version: ${ env.RELEASE_VERSION} "
116
- echo " Development version: ${ env.DEVELOPMENT_VERSION} "
117
- echo " Version family: ${ env.VERSION_FAMILY} "
118
167
119
168
// Determine version id to check if Jira version exists
120
- sh( script : " .release/scripts/determine-jira-version-id.sh ${ env.JIRA_KEY} ${ env.VERSION_BASIS } " , returnStdout : true )
169
+ sh " .release/scripts/determine-jira-version-id.sh ${ env.JIRA_KEY} ${ releaseVersion.withoutFinalQualifier } "
121
170
}
122
171
}
123
172
}
124
173
stage(' Release prepare' ) {
125
174
steps {
126
175
script {
127
- dir(' .release/scripts' ) {
128
- checkout scmGit(branches : [[name : ' */main' ]], extensions : [], userRemoteConfigs : [[credentialsId : ' ed25519.Hibernate-CI.github.com' , url : ' https://github.com/hibernate/hibernate-release-scripts.git' ]])
129
- }
130
- configFileProvider([configFile(fileId : ' release.config.ssh' , targetLocation : " ${ env.HOME} /.ssh/config" ), configFile(fileId : ' release.config.ssh.knownhosts' , targetLocation : " ${ env.HOME} /.ssh/known_hosts" )]) {
131
- sshagent([' ed25519.Hibernate-CI.github.com' , ' hibernate.filemgmt.jboss.org' , ' hibernate-ci.frs.sourceforge.net' ]) {
132
- // set release version
133
- // update changelog from JIRA
134
- // tags the version
135
- // changes the version to the provided development version
136
- withEnv([
137
- " BRANCH=${ env.GIT_BRANCH} " ,
138
- " DISABLE_REMOTE_GRADLE_CACHE=true"
139
- ]) {
140
- sh " .release/scripts/prepare-release.sh ${ env.PROJECT} ${ env.RELEASE_VERSION} ${ env.DEVELOPMENT_VERSION} "
141
- }
142
- }
176
+ checkoutReleaseScripts()
177
+
178
+ configFileProvider([
179
+ configFile(fileId : ' release.config.ssh' , targetLocation : " ${ env.HOME} /.ssh/config" ),
180
+ configFile(fileId : ' release.config.ssh.knownhosts' , targetLocation : " ${ env.HOME} /.ssh/known_hosts" )
181
+ ]) {
182
+ sshagent([' ed25519.Hibernate-CI.github.com' , ' hibernate.filemgmt.jboss.org' , ' hibernate-ci.frs.sourceforge.net' ]) {
183
+ // set release version
184
+ // update changelog from JIRA
185
+ // tags the version
186
+ // changes the version to the provided development version
187
+ withEnv([
188
+ " BRANCH=${ env.GIT_BRANCH} " ,
189
+ " DISABLE_REMOTE_GRADLE_CACHE=true" ,
190
+ // Increase the amount of memory for this part since asciidoctor doc rendering consumes a lot of metaspace
191
+ " GRADLE_OPTS=-Dorg.gradle.jvmargs='-Dlog4j2.disableJmx -Xmx4g -XX:MaxMetaspaceSize=768m -XX:+HeapDumpOnOutOfMemoryError -Duser.language=en -Duser.country=US -Duser.timezone=UTC -Dfile.encoding=UTF-8'"
192
+ ]) {
193
+ sh " .release/scripts/prepare-release.sh ${ env.PROJECT} ${ env.RELEASE_VERSION} ${ env.DEVELOPMENT_VERSION} "
194
+ }
195
+ }
143
196
}
144
197
}
145
198
}
146
199
}
147
200
stage(' Publish release' ) {
148
201
steps {
149
202
script {
150
- dir(' .release/scripts' ) {
151
- checkout scmGit(branches : [[name : ' */main' ]], extensions : [], userRemoteConfigs : [[credentialsId : ' ed25519.Hibernate-CI.github.com' , url : ' https://github.com/hibernate/hibernate-release-scripts.git' ]])
152
- }
153
- configFileProvider([configFile(fileId : ' release.config.ssh' , targetLocation : " ${ env.HOME} /.ssh/config" ), configFile(fileId : ' release.config.ssh.knownhosts' , targetLocation : " ${ env.HOME} /.ssh/known_hosts" )]) {
203
+ checkoutReleaseScripts()
204
+
205
+ configFileProvider([
206
+ configFile(fileId : ' release.config.ssh' , targetLocation : " ${ env.HOME} /.ssh/config" ),
207
+ configFile(fileId : ' release.config.ssh.knownhosts' , targetLocation : " ${ env.HOME} /.ssh/known_hosts" )
208
+ ]) {
154
209
withCredentials([
155
210
// https://github.com/gradle-nexus/publish-plugin#publishing-to-maven-central-via-sonatype-ossrh
156
211
usernamePassword(credentialsId : ' ossrh.sonatype.org' , passwordVariable : ' ORG_GRADLE_PROJECT_sonatypePassword' , usernameVariable : ' ORG_GRADLE_PROJECT_sonatypeUsername' ),
@@ -177,10 +232,12 @@ pipeline {
177
232
stage(' Website release' ) {
178
233
steps {
179
234
script {
180
- dir(' .release/scripts' ) {
181
- checkout scmGit(branches : [[name : ' */main' ]], extensions : [], userRemoteConfigs : [[credentialsId : ' ed25519.Hibernate-CI.github.com' , url : ' https://github.com/hibernate/hibernate-release-scripts.git' ]])
182
- }
183
- configFileProvider([configFile(fileId : ' release.config.ssh' , targetLocation : " ${ env.HOME} /.ssh/config" ), configFile(fileId : ' release.config.ssh.knownhosts' , targetLocation : " ${ env.HOME} /.ssh/known_hosts" )]) {
235
+ checkoutReleaseScripts()
236
+
237
+ configFileProvider([
238
+ configFile(fileId : ' release.config.ssh' , targetLocation : " ${ env.HOME} /.ssh/config" ),
239
+ configFile(fileId : ' release.config.ssh.knownhosts' , targetLocation : " ${ env.HOME} /.ssh/known_hosts" )
240
+ ]) {
184
241
withCredentials([
185
242
gitUsernamePassword(credentialsId : ' username-and-token.Hibernate-CI.github.com' , gitToolName : ' Default' )
186
243
]) {
@@ -202,9 +259,7 @@ pipeline {
202
259
stage(' GitHub release' ) {
203
260
steps {
204
261
script {
205
- dir(' .release/scripts' ) {
206
- checkout scmGit(branches : [[name : ' */main' ]], extensions : [], userRemoteConfigs : [[credentialsId : ' ed25519.Hibernate-CI.github.com' , url : ' https://github.com/hibernate/hibernate-release-scripts.git' ]])
207
- }
262
+ checkoutReleaseScripts()
208
263
withCredentials([string(credentialsId : ' Hibernate-CI.github.com' , variable : ' GITHUB_API_TOKEN' )]) {
209
264
sh " .release/scripts/github-release.sh ${ env.SCRIPT_OPTIONS} ${ env.PROJECT} ${ env.RELEASE_VERSION} "
210
265
}
@@ -219,4 +274,4 @@ pipeline {
219
274
}
220
275
}
221
276
}
222
- }
277
+ }
0 commit comments