Properly collect project version number for CI jobs.

The outputs on Jenkins are very different than the outputs when run locally. They must be gathered in a more sophisticated fashion that grepping console logs.
This commit is contained in:
Greg L. Turnquist
2021-01-20 14:31:07 -06:00
parent 8ee2ada5ac
commit 75e0809ab2
2 changed files with 18 additions and 9 deletions

13
Jenkinsfile vendored
View File

@@ -183,11 +183,8 @@ pipeline {
steps {
script {
// Warm up this plugin quietly before using it.
sh "./mvnw -q org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dexpression=project.version"
PROJECT_VERSION = sh(
script: "./mvnw org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dexpression=project.version -o | grep -v INFO",
script: "ci/version.sh",
returnStdout: true
).trim()
@@ -201,14 +198,13 @@ pipeline {
RELEASE_TYPE = 'snapshot'
}
if (RELEASE_TYPE == 'release') {
sh "PROFILE=distribute,central USERNAME=${SONATYPE_USR} PASSWORD=${SONATYPE_PSW} ci/build-and-deploy-to-maven-central.sh ${PROJECT_VERSION}"
slackSend(
color: (currentBuild.currentResult == 'SUCCESS') ? 'good' : 'danger',
channel: '#spring-ws',
message: "@here Spring WS ${PROJECT_VERSION} is staged on Sonatype awaiting closure and release.")
color: (currentBuild.currentResult == 'SUCCESS') ? 'good' : 'danger',
channel: '#spring-ws',
message: "@here Spring WS ${PROJECT_VERSION} is staged on Sonatype awaiting closure and release.")
} else {
sh "PROFILE=distribute,${RELEASE_TYPE} ci/build-and-deploy-to-artifactory.sh"
}
@@ -234,7 +230,6 @@ pipeline {
steps {
script {
sh 'MAVEN_OPTS="-Duser.name=jenkins -Duser.home=/tmp/jenkins-home" ./mvnw -Pdistribute,docs ' +
'-Dartifactory.server=https://repo.spring.io ' +
"-Dartifactory.username=${ARTIFACTORY_USR} " +

14
ci/version.sh Executable file
View File

@@ -0,0 +1,14 @@
#!/bin/bash
set -euo pipefail
RAW_VERSION=`MAVEN_OPTS="-Duser.name=jenkins -Duser.home=/tmp/jenkins-home" ./mvnw \
org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate \
-Dexpression=project.version -q -DforceStdout`
# Split things up
VERSION_PARTS=($RAW_VERSION)
# Grab the last part, which is the actual version number.
echo ${VERSION_PARTS[${#VERSION_PARTS[@]}-1]}