Skip to content

Instantly share code, notes, and snippets.

@lielran
Last active November 16, 2019 05:31
Show Gist options
  • Save lielran/9385790 to your computer and use it in GitHub Desktop.
Save lielran/9385790 to your computer and use it in GitHub Desktop.
Jenkins get Maven Version and save it to properties file
echo "######Getting Dev Version From Pom##########" > /dev/null 2>&1
SNAPSHOT="-SNAPSHOT";
DEV_VERSION=$(mvn org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dq -Dexpression=project.version | grep -v '\[');
export RELEASE_VERSION="$(echo $DEV_VERSION | sed "s@$SNAPSHOT@@").$BUILD_NUMBER";
echo "#############################################" > /dev/null 2>&1
echo "###Development Version is : $DEV_VERSION ###" > /dev/null 2>&1
echo "###Release Version is : $RELEASE_VERSION ###" > /dev/null 2>&1
echo "#############################################" > /dev/null 2>&1
echo DEV_VERSION =$(echo $DEV_VERSION) > propsfile
echo RELEASE_VERSION =$(echo $RELEASE_VERSION ) > propsfile
SNAPSHOT="-SNAPSHOT";
DEV_VERSION=$(mvn org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dq -Dexpression=project.version | grep -Ev '(^\[|Download\w+:)' );
echo "######Current Version is: $DEV_VERSION ##########" > /dev/null 2>&1
substring=$SNAPSHOT
if [ "${DEV_VERSION/$substring}" = "$DEV_VERSION" ] ; then
echo "${substring} is not in ${DEV_VERSION}"
echo "this is release version --> bump the version"
export RELEASE_VERSION="$(echo ${DEV_VERSION%.*}).$BUILD_NUMBER";
else
echo "${substring} was found in ${DEV_VERSION}"
export RELEASE_VERSION="$(echo $DEV_VERSION | sed "s@$SNAPSHOT@@").$BUILD_NUMBER";
fi
echo "#############################################" > /dev/null 2>&1
echo "###Development Version is : $DEV_VERSION ###" > /dev/null 2>&1
echo "###Release Version is : $RELEASE_VERSION ###" > /dev/null 2>&1
echo "#############################################" > /dev/null 2>&1
@wanghaifeng
Copy link

wanghaifeng commented Jun 28, 2018

Thanks for the scripts.

Add "-B" with mvn command will help on first run the scripts.
Because mvn will download jar files for first run and make grep command return wrong value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment