Skip to content

Commit cbcce19

Browse files
committed
[#304] Add a release Jenkinsfile
1 parent 09253ec commit cbcce19

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

ci/release/Jenkinsfile

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
* Jakarta Validation API
3+
*
4+
* License: Apache License, Version 2.0
5+
* See the license.txt file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>.
6+
*/
7+
8+
@Library('releng-pipeline') _
9+
10+
// Avoid running the pipeline on branch indexing
11+
if (currentBuild.getBuildCauses().toString().contains('BranchIndexingCause')) {
12+
print "INFO: Build skipped due to trigger being Branch Indexing"
13+
currentBuild.result = 'NOT_BUILT'
14+
return
15+
}
16+
17+
pipeline {
18+
agent {
19+
label 'basic'
20+
}
21+
tools {
22+
maven 'apache-maven-3.9.11'
23+
jdk 'openjdk-jdk25-latest'
24+
}
25+
options {
26+
buildDiscarder logRotator(daysToKeepStr: '30', numToKeepStr: '10')
27+
disableConcurrentBuilds(abortPrevious: false)
28+
}
29+
parameters {
30+
string(
31+
name: 'RELEASE_VERSION',
32+
defaultValue: '',
33+
description: 'The version to be released, e.g. 4.0.0.',
34+
trim: true
35+
)
36+
string(
37+
name: 'DEVELOPMENT_VERSION',
38+
defaultValue: '',
39+
description: 'The next version to be used after the release, e.g. 4.0.1-SNAPSHOT.',
40+
trim: true
41+
)
42+
}
43+
stages {
44+
stage('Publish Release to Maven Central') {
45+
when {
46+
beforeAgent true
47+
// Releases must be triggered explicitly
48+
// This is just for safety; normally the Jenkins job for this pipeline
49+
// should be configured to "Suppress automatic SCM triggering"
50+
// See https://stackoverflow.com/questions/58259326/prevent-jenkins-multibranch-pipeline-from-triggering-builds-for-new-branches
51+
triggeredBy cause: "UserIdCause"
52+
}
53+
steps {
54+
script {
55+
// Check that all the necessary parameters are set
56+
if (!params.RELEASE_VERSION) {
57+
throw new IllegalArgumentException("Missing value for parameter RELEASE_VERSION.")
58+
}
59+
if (!params.DEVELOPMENT_VERSION) {
60+
throw new IllegalArgumentException("Missing value for parameter DEVELOPMENT_VERSION.")
61+
}
62+
echo "Performing release for version ${params.RELEASE_VERSION}"
63+
64+
withCredentials([file(credentialsId: 'secret-subkeys.asc', variable: 'KEYRING')]) {
65+
withMaven(mavenLocalRepo: env.WORKSPACE_TMP + '/.m2repository') {
66+
sh 'gpg --batch --import "${KEYRING}"'
67+
sh 'for fpr in $(gpg --list-keys --with-colons | awk -F: \'/fpr:/ {print $10}\' | sort -u); do echo -e "5\ny\n" | gpg --batch --command-fd 0 --expert --edit-key ${fpr} trust; done'
68+
69+
// Set up git so that we can create commits
70+
sh 'git config --local user.name "Jakarta Validation"'
71+
sh 'git config --local user.email "bean-validation-dev@eclipse.org"'
72+
73+
// update version:
74+
sh "./mvnw -Prelocation clean versions:set -DnewVersion=${params.RELEASE_VERSION} -DgenerateBackupPoms=false"
75+
76+
// commit and tag the "release version":
77+
sh "git commit -a -m '[Jenkins release job] Preparing release ${params.RELEASE_VERSION}'"
78+
sh "git tag -a -m 'Release ${params.RELEASE_VERSION}' ${params.RELEASE_VERSION}"
79+
80+
// deploy to Maven Central:
81+
sh "./mvnw clean deploy -Poss-release -Psnapshots -DskipTests=true"
82+
83+
// reset the version back to dev:
84+
sh "./mvnw -Prelocation clean versions:set -DnewVersion=${params.DEVELOPMENT_VERSION} -DgenerateBackupPoms=false"
85+
86+
// commit the dev version and push all back to git:
87+
sh "git commit -a -m '[Jenkins release job] Preparing next development iteration'"
88+
89+
sh "git push origin HEAD:${env.GIT_BRANCH}"
90+
sh "git push origin ${params.RELEASE_VERSION}"
91+
}
92+
}
93+
}
94+
}
95+
}
96+
}
97+
}

0 commit comments

Comments
 (0)