'Accessing released version using Maven Release
I'm building a custom pipeline in Jenkins, where I'm invoking Maven Release plugin and I would need to store the released artifact version. Command run on Jenkins:
sh 'mvn -Dusername=${GIT_USERNAME} -DskipTests -Darguments=-DskipTests --batch-mode clean release:clean release:prepare release:perform'
Artifact versions:
Prior to release: 0.0.1-SNAPSHOT
Released: 0.0.1
After release: 0.0.2-SNAPSHOT
I would like to be able to store released versions "0.0.1" to be reused later in sh or Groovy script, how can I do that?
Solution 1:[1]
You can get the version using the help plugin:
RESULT=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
echo $RESULT
See https://maven.apache.org/plugins/maven-help-plugin/evaluate-mojo.html
This will include the -SNAPSHOT suffix, so you'll need to remove that:
RESULT=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout | sed s/-SNAPSHOT//)
echo $RESULT
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
