|
| 1 | +/* |
| 2 | + * Hibernate Tools, Tooling for your Hibernate Projects |
| 3 | + * |
| 4 | + * Copyright 2016-2024 Red Hat, Inc. |
| 5 | + * |
| 6 | + * Licensed under the GNU Lesser General Public License (LGPL), |
| 7 | + * version 2.1 or later (the "License"). |
| 8 | + * You may not use this file except in compliance with the License. |
| 9 | + * You may read the licence in the 'lgpl.txt' file in the root folder of |
| 10 | + * project or obtain a copy at |
| 11 | + * |
| 12 | + * http://www.gnu.org/licenses/lgpl-2.1.html |
| 13 | + * |
| 14 | + * Unless required by applicable law or agreed to in writing, software |
| 15 | + * distributed under the License is distributed on an "AS IS" basis, |
| 16 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | + * See the License for the specific language governing permissions and |
| 18 | + * limitations under the License. |
| 19 | + */ |
| 20 | +@Library('hibernate-jenkins-pipeline-helpers') _ |
| 21 | + |
| 22 | +import org.hibernate.jenkins.pipeline.helpers.version.Version |
| 23 | + |
| 24 | +pipeline { |
| 25 | + agent { |
| 26 | + label 'Release' |
| 27 | + } |
| 28 | + tools { |
| 29 | + maven 'Apache Maven 3.9' |
| 30 | + jdk 'OpenJDK 21 Latest' |
| 31 | + } |
| 32 | + options { |
| 33 | + buildDiscarder logRotator(daysToKeepStr: '30', numToKeepStr: '10') |
| 34 | + disableConcurrentBuilds(abortPrevious: false) |
| 35 | + } |
| 36 | + parameters { |
| 37 | + string( |
| 38 | + name: 'RELEASE_VERSION', |
| 39 | + defaultValue: '', |
| 40 | + description: 'The version to be released, e.g. 6.3.3.Final.', |
| 41 | + trim: true |
| 42 | + ) |
| 43 | + string( |
| 44 | + name: 'DEVELOPMENT_VERSION', |
| 45 | + defaultValue: '', |
| 46 | + description: 'The next version to be used after the release, e.g. 6.3.4-SNAPSHOT.', |
| 47 | + trim: true |
| 48 | + ) |
| 49 | + booleanParam( |
| 50 | + name: 'RELEASE_DRY_RUN', |
| 51 | + defaultValue: false, |
| 52 | + description: 'If true, just simulate the release, without pushing any commits or tags, and without uploading any artifacts or documentation.' |
| 53 | + ) |
| 54 | + } |
| 55 | + stages { |
| 56 | + stage('Release') { |
| 57 | + when { |
| 58 | + beforeAgent true |
| 59 | + // Releases must be triggered explicitly |
| 60 | + // This is just for safety; normally the Jenkins job for this pipeline |
| 61 | + // should be configured to "Suppress automatic SCM triggering" |
| 62 | + // See https://stackoverflow.com/questions/58259326/prevent-jenkins-multibranch-pipeline-from-triggering-builds-for-new-branches |
| 63 | + triggeredBy cause: "UserIdCause" |
| 64 | + } |
| 65 | + steps { |
| 66 | + script { |
| 67 | + // Check that all the necessary parameters are set |
| 68 | + if (!params.RELEASE_VERSION) { |
| 69 | + throw new IllegalArgumentException("Missing value for parameter RELEASE_VERSION.") |
| 70 | + } |
| 71 | + if (!params.DEVELOPMENT_VERSION) { |
| 72 | + throw new IllegalArgumentException("Missing value for parameter DEVELOPMENT_VERSION.") |
| 73 | + } |
| 74 | + |
| 75 | + def releaseVersion = Version.parseReleaseVersion(params.RELEASE_VERSION) |
| 76 | + def developmentVersion = Version.parseDevelopmentVersion(params.DEVELOPMENT_VERSION) |
| 77 | + echo "Performing full release for version ${releaseVersion.toString()}" |
| 78 | + |
| 79 | + withMaven(mavenSettingsConfig: params.RELEASE_DRY_RUN ? null : 'ci-hibernate.deploy.settings.maven', |
| 80 | + mavenLocalRepo: env.WORKSPACE_TMP + '/.m2repository') { |
| 81 | + configFileProvider([configFile(fileId: 'release.config.ssh', targetLocation: env.HOME + '/.ssh/config'), |
| 82 | + configFile(fileId: 'release.config.ssh.knownhosts', targetLocation: env.HOME + '/.ssh/known_hosts')]) { |
| 83 | + // using MAVEN_GPG_PASSPHRASE (the default env variable name for passphrase in maven gpg plugin) |
| 84 | + withCredentials([file(credentialsId: 'release.gpg.private-key', variable: 'RELEASE_GPG_PRIVATE_KEY_PATH'), |
| 85 | + string(credentialsId: 'release.gpg.passphrase', variable: 'MAVEN_GPG_PASSPHRASE')]) { |
| 86 | + sshagent(['ed25519.Hibernate-CI.github.com', 'hibernate.filemgmt.jboss.org', 'hibernate-ci.frs.sourceforge.net']) { |
| 87 | + sh 'cat $HOME/.ssh/config' |
| 88 | + sh 'git clone https://github.com/hibernate/hibernate-release-scripts.git' |
| 89 | + env.RELEASE_GPG_HOMEDIR = env.WORKSPACE_TMP + '/.gpg' |
| 90 | + sh """ |
| 91 | + bash -xe hibernate-release-scripts/release.sh ${params.RELEASE_DRY_RUN ? '-d' : ''} \ |
| 92 | + tools ${releaseVersion.toString()} ${developmentVersion.toString()} |
| 93 | + """ |
| 94 | + } |
| 95 | + } |
| 96 | + } |
| 97 | + } |
| 98 | + } |
| 99 | + } |
| 100 | + } |
| 101 | + } |
| 102 | + post { |
| 103 | + always { |
| 104 | + notifyBuildResult notifySuccessAfterSuccess: true, maintainers: '[email protected]' |
| 105 | + } |
| 106 | + } |
| 107 | +} |
0 commit comments