Skip to content

Commit d37fc1c

Browse files
committed
[#1956] Add Jenkins release pipeline configuration
1 parent 65627f4 commit d37fc1c

File tree

1 file changed

+191
-0
lines changed

1 file changed

+191
-0
lines changed

ci/release/Jenkinsfile

+191
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
#! /usr/bin/groovy
2+
/*
3+
* Hibernate, Relational Persistence for Idiomatic Java
4+
*
5+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
6+
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
7+
*/
8+
9+
/*
10+
* See https://github.com/hibernate/hibernate-jenkins-pipeline-helpers
11+
*/
12+
@Library('[email protected]') _
13+
14+
import org.hibernate.jenkins.pipeline.helpers.version.Version
15+
16+
// --------------------------------------------
17+
// Global build configuration
18+
env.PROJECT = "reactive"
19+
env.JIRA_KEY = "HREACT"
20+
def RELEASE_ON_PUSH = false // Set to `true` *only* on branches where you want a release on each push.
21+
22+
print "INFO: env.PROJECT = ${env.PROJECT}"
23+
print "INFO: env.JIRA_KEY = ${env.JIRA_KEY}"
24+
print "INFO: RELEASE_ON_PUSH = ${RELEASE_ON_PUSH}"
25+
26+
// --------------------------------------------
27+
// Build conditions
28+
29+
// Avoid running the pipeline on branch indexing
30+
if (currentBuild.getBuildCauses().toString().contains('BranchIndexingCause')) {
31+
print "INFO: Build skipped due to trigger being Branch Indexing"
32+
currentBuild.result = 'NOT_BUILT'
33+
return
34+
}
35+
36+
def manualRelease = currentBuild.getBuildCauses().toString().contains( 'UserIdCause' )
37+
38+
// Only do automatic release on branches where we opted in
39+
if ( !manualRelease && !RELEASE_ON_PUSH ) {
40+
print "INFO: Build skipped because automated releases are disabled on this branch. See constant RELEASE_ON_PUSH in ci/release/Jenkinsfile"
41+
currentBuild.result = 'NOT_BUILT'
42+
return
43+
}
44+
45+
// --------------------------------------------
46+
// Reusable methods
47+
48+
def checkoutReleaseScripts() {
49+
dir('.release/scripts') {
50+
checkout scmGit(branches: [[name: '*/main']], extensions: [],
51+
userRemoteConfigs: [[credentialsId: 'ed25519.Hibernate-CI.github.com',
52+
url: 'https://github.com/hibernate/hibernate-release-scripts.git']])
53+
}
54+
}
55+
56+
// --------------------------------------------
57+
// Pipeline
58+
59+
pipeline {
60+
agent {
61+
label 'Worker&&Containers'
62+
}
63+
tools {
64+
jdk 'OpenJDK 11 Latest'
65+
}
66+
options {
67+
buildDiscarder logRotator(daysToKeepStr: '30', numToKeepStr: '10')
68+
rateLimitBuilds(throttle: [count: 1, durationName: 'day', userBoost: true])
69+
disableConcurrentBuilds(abortPrevious: false)
70+
preserveStashes()
71+
}
72+
parameters {
73+
string(
74+
name: 'RELEASE_VERSION',
75+
defaultValue: '',
76+
description: 'The version to be released, e.g. 2.4.0.Final. Mandatory for manual releases, to prevent mistakes.',
77+
trim: true
78+
)
79+
string(
80+
name: 'DEVELOPMENT_VERSION',
81+
defaultValue: '',
82+
description: 'The next version to be used after the release, e.g. 2.4.1-SNAPSHOT. If not set, determined automatically from the release version.',
83+
trim: true
84+
)
85+
booleanParam(
86+
name: 'RELEASE_DRY_RUN',
87+
defaultValue: false,
88+
description: 'If true, just simulate the release, without pushing any commits or tags, and without uploading any artifacts or documentation.'
89+
)
90+
}
91+
stages {
92+
stage('Release check') {
93+
steps {
94+
script {
95+
checkoutReleaseScripts()
96+
97+
def currentVersion = Version.parseDevelopmentVersion( sh(
98+
script: ".release/scripts/determine-current-version.sh ${env.PROJECT}",
99+
returnStdout: true
100+
).trim() )
101+
echo "Workspace version: ${currentVersion}"
102+
103+
def releaseVersion
104+
def developmentVersion
105+
106+
if ( manualRelease ) {
107+
echo "Release was requested manually"
108+
109+
if ( !params.RELEASE_VERSION ) {
110+
throw new IllegalArgumentException( 'Missing value for parameter RELEASE_VERSION. This parameter must be set explicitly to prevent mistakes.' )
111+
}
112+
releaseVersion = Version.parseReleaseVersion( params.RELEASE_VERSION )
113+
114+
if ( !releaseVersion.toString().startsWith( currentVersion.family + '.' ) ) {
115+
throw new IllegalArgumentException( "RELEASE_VERSION = $releaseVersion, which is different from the family of CURRENT_VERSION = $currentVersion. Did you make a mistake?" )
116+
}
117+
}
118+
else {
119+
echo "Release was triggered automatically"
120+
121+
// Avoid doing an automatic release for commits from a release
122+
def lastCommitter = sh(script: 'git show -s --format=\'%an\'', returnStdout: true)
123+
def secondLastCommitter = sh(script: 'git show -s --format=\'%an\' HEAD~1', returnStdout: true)
124+
if (lastCommitter == 'Hibernate-CI' && secondLastCommitter == 'Hibernate-CI') {
125+
print "INFO: Automatic release skipped because last commits were for the previous release"
126+
currentBuild.result = 'ABORTED'
127+
return
128+
}
129+
130+
releaseVersion = Version.parseReleaseVersion( sh(
131+
script: ".release/scripts/determine-release-version.sh ${currentVersion}",
132+
returnStdout: true
133+
).trim() )
134+
}
135+
echo "Release version: ${releaseVersion}"
136+
137+
if ( !params.DEVELOPMENT_VERSION ) {
138+
developmentVersion = Version.parseDevelopmentVersion( sh(
139+
script: ".release/scripts/determine-development-version.sh ${releaseVersion}",
140+
returnStdout: true
141+
).trim() )
142+
}
143+
else {
144+
developmentVersion = Version.parseDevelopmentVersion( params.DEVELOPMENT_VERSION )
145+
}
146+
echo "Development version: ${developmentVersion}"
147+
148+
env.RELEASE_VERSION = releaseVersion.toString()
149+
env.DEVELOPMENT_VERSION = developmentVersion.toString()
150+
// Dry run is not supported at the moment
151+
env.SCRIPT_OPTIONS = params.RELEASE_DRY_RUN ? "-d" : ""
152+
153+
// Determine version id to check if Jira version exists
154+
// This step doesn't work for Hibernate Reactive (the project has been created with a different type on JIRA)
155+
// sh ".release/scripts/determine-jira-version-id.sh ${env.JIRA_KEY} ${releaseVersion.withoutFinalQualifier}"
156+
}
157+
}
158+
}
159+
stage('Publish release') {
160+
steps {
161+
script {
162+
checkoutReleaseScripts()
163+
164+
configFileProvider([
165+
configFile(fileId: 'release.config.ssh', targetLocation: "${env.HOME}/.ssh/config"),
166+
configFile(fileId: 'release.config.ssh.knownhosts', targetLocation: "${env.HOME}/.ssh/known_hosts")
167+
]) {
168+
withCredentials([
169+
usernamePassword(credentialsId: 'ossrh.sonatype.org', passwordVariable: 'OSSRH_PASSWORD', usernameVariable: 'OSSRH_USER'),
170+
usernamePassword(credentialsId: 'gradle-plugin-portal-api-key', passwordVariable: 'PLUGIN_PORTAL_PASSWORD', usernameVariable: 'PLUGIN_PORTAL_USERNAME'),
171+
file(credentialsId: 'release.gpg.private-key', variable: 'RELEASE_GPG_PRIVATE_KEY_PATH'),
172+
string(credentialsId: 'release.gpg.passphrase', variable: 'RELEASE_GPG_PASSPHRASE'),
173+
gitUsernamePassword(credentialsId: 'username-and-token.Hibernate-CI.github.com', gitToolName: 'Default')
174+
]) {
175+
sshagent(['ed25519.Hibernate-CI.github.com', 'hibernate.filemgmt.jboss.org', 'hibernate-ci.frs.sourceforge.net']) {
176+
// performs documentation upload and Sonatype release
177+
// push to github
178+
sh ".release/scripts/publish.sh ${env.SCRIPT_OPTIONS} ${env.PROJECT} ${env.RELEASE_VERSION} ${env.DEVELOPMENT_VERSION} ${env.GIT_BRANCH}"
179+
}
180+
}
181+
}
182+
}
183+
}
184+
}
185+
}
186+
post {
187+
always {
188+
notifyBuildResult notifySuccessAfterSuccess: true, maintainers: '[email protected]'
189+
}
190+
}
191+
}

0 commit comments

Comments
 (0)