Skip to content

Instantly share code, notes, and snippets.

@siavashs
Last active May 31, 2016 12:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save siavashs/db4a7d32b5ee595deea4c916e3697822 to your computer and use it in GitHub Desktop.
Save siavashs/db4a7d32b5ee595deea4c916e3697822 to your computer and use it in GitHub Desktop.
Nexus artifact deployment script
#!/bin/bash
# Author: Siavash Safi <siavash.safi@gmail.com>
# Nexus artifact deployment script
# Original solution from https://support.sonatype.com/hc/en-us/articles/213465818-How-can-I-programatically-upload-an-artifact-into-Nexus-
groupId=`xmlstarlet sel -t -v '//_:project/_:groupId' pom.xml`
artifactId=`xmlstarlet sel -t -v '//_:project/_:artifactId' pom.xml`
version=`xmlstarlet sel -t -v '//_:project/_:version' pom.xml`
packaging=`xmlstarlet sel -t -v '//_:project/_:packaging' pom.xml`
repo="snapshots"
usage () {
echo "USAGE: $0 -r | -s"
echo -e "\t-r\t deploy to releases repository"
echo -e "\t-s\t deploy to snapshots repository (default)"
echo -e "\t-u\t repository base url (required)"
exit $1
}
while getopts ":hrsu:" opt; do
case $opt in
h)
usage 0
;;
r)
release=1
if [ ! -z "$snapshot" ]
then
echo "you cannot use -r and -s at the same time!"
exit 1
fi
repo="releases"
;;
s)
snapshot=1
if [ ! -z "$release" ]
then
echo "you cannot use -r and -s at the same time!"
exit 1
fi
repo="snapshots"
;;
u)
url=$OPTARG
;;
\?)
echo "Invalid option: -$OPTARG" >&2
usage 1
;;
esac
done
if [ ! "$url" ]
then
echo "repository base url must be provided with -u option!"
usage
fi
echo "deploying to $url/$repo ..."
if [ -e pom.xml ]
then
mvn deploy:deploy-file \
-DgroupId=$groupId \
-DartifactId=$artifactId \
-Dversion=$version \
-DgeneratePom=false \
-Dpackaging=$packaging \
-DrepositoryId=nexus \
-Durl=$url/$repo \
-DpomFile=pom.xml \
-Dfile=target/$artifactId-$version.$packaging
else
mvn deploy:deploy-file \
-DgroupId=$groupId \
-DartifactId=$artifactId \
-Dversion=$version \
-DgeneratePom=true \
-Dpackaging=$packaging \
-DrepositoryId=nexus \
-Durl=$url/$repo \
-Dfile=target/$artifactId-$version.$packaging
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment