1111 */  
12121313
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+ 
1428//  Avoid running the pipeline on branch indexing
1529if  (currentBuild. getBuildCauses(). toString(). contains(' BranchIndexingCause'  )) {
1630	print  " INFO: Build skipped due to trigger being Branch Indexing" 
1731	currentBuild. result =  ' NOT_BUILT' 
1832	return 
1933}
2034
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
2364
2465pipeline {
2566	agent {
2667		label ' Worker&&Containers' 
2768	}
69+ 	triggers {
70+ 		//  Run every week Sunday midnight
71+ 		cron(' 0 0 * * 0'  )
72+ 	}
2873	tools {
2974		jdk ' OpenJDK 11 Latest' 
3075	}
3176	options {
3277		buildDiscarder logRotator(daysToKeepStr : ' 30'  , numToKeepStr : ' 10'  )
33- 		rateLimitBuilds(throttle : [count : 1 , durationName : ' day'  , userBoost : true ])
3478		disableConcurrentBuilds(abortPrevious : false )
3579		preserveStashes()
3680	}
3781	parameters {
3882		string(
3983				name : ' RELEASE_VERSION'  ,
4084				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. '  ,
4286				trim : true 
4387		)
4488		string(
4589				name : ' DEVELOPMENT_VERSION'  ,
4690				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. '  ,
4892				trim : true 
4993		)
5094		booleanParam(
@@ -61,96 +105,107 @@ pipeline {
61105					print  " INFO: params.DEVELOPMENT_VERSION = ${ params.DEVELOPMENT_VERSION} " 
62106					print  " INFO: params.RELEASE_DRY_RUN? = ${ params.RELEASE_DRY_RUN} " 
63107
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()
73109
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(
79111							script : " .release/scripts/determine-current-version.sh ${ env.PROJECT} "  ,
80112							returnStdout : true 
81- 					). trim()
113+ 					). trim() )
114+ 					echo " Workspace version: ${ currentVersion} " 
82115
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+ 						}
88132					}
89133					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() )
91150					}
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} "  ,
95156								returnStdout : true 
96- 						). trim()
157+ 						). trim() ) 
97158					}
98159					else  {
99- 						env . DEVELOPMENT_VERSION  =  params. DEVELOPMENT_VERSION 
160+ 						developmentVersion  =  Version . parseDevelopmentVersion(  params. DEVELOPMENT_VERSION  ) 
100161					}
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()
113166					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} " 
118167
119168					//  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 } " 
121170				}
122171			}
123172		}
124173		stage(' Release prepare'  ) {
125174			steps {
126175				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+ 						}
143196					}
144197				}
145198			}
146199		}
147200		stage(' Publish release'  ) {
148201			steps {
149202				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+ 					]) {
154209						withCredentials([
155210							//  https://github.com/gradle-nexus/publish-plugin#publishing-to-maven-central-via-sonatype-ossrh
156211							usernamePassword(credentialsId : ' ossrh.sonatype.org'  , passwordVariable : ' ORG_GRADLE_PROJECT_sonatypePassword'  , usernameVariable : ' ORG_GRADLE_PROJECT_sonatypeUsername'  ),
@@ -177,10 +232,12 @@ pipeline {
177232		stage(' Website release'  ) {
178233			steps {
179234				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+ 					]) {
184241						withCredentials([
185242								gitUsernamePassword(credentialsId : ' username-and-token.Hibernate-CI.github.com'  , gitToolName : ' Default'  )
186243						]) {
@@ -202,9 +259,7 @@ pipeline {
202259		stage(' GitHub release'  ) {
203260			steps {
204261				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()
208263					withCredentials([string(credentialsId : ' Hibernate-CI.github.com'  , variable : ' GITHUB_API_TOKEN'  )]) {
209264						sh " .release/scripts/github-release.sh ${ env.SCRIPT_OPTIONS}   ${ env.PROJECT}   ${ env.RELEASE_VERSION} " 
210265					}
@@ -219,4 +274,4 @@ pipeline {
219274 			}
220275 		}
221276 	}
222- }
277+ }
0 commit comments