Created
January 31, 2018 14:31
-
-
Save benjefferies/106d53e3178e1627bcad4784f6fe7fe1 to your computer and use it in GitHub Desktop.
Download latest artifact inspired by https://gist.github.com/suicide/b9d3a4f26a68f68de433
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# downloads latest version of an artifact from artifactory | |
set -e | |
usage(){ | |
echo "Usage: $*" >&2 | |
exit 64 | |
} | |
repo="" | |
group="" | |
artifact="" | |
classifier="" | |
while getopts r:g:a:c: OPT; do | |
case "${OPT}" in | |
r) repo="${OPTARG}";; | |
g) group="${OPTARG}";; | |
a) artifact="${OPTARG}";; | |
c) classifier="${OPTARG}";; | |
esac | |
done | |
shift $(( $OPTIND - 1 )) | |
if [ -z "${repo}" ] || [ -z "${group}" ] || [ -z "${artifact}" ]; then | |
usage "-r REPOSITORY -g GROUPID -a ARTIFACTID [-c CLASSIFIER]" | |
fi | |
# Maven artifact location | |
ga=${group//./\/}/$artifact | |
repopath=$repo/$ga | |
version=$(curl -s $repopath/maven-metadata.xml | grep latest | sed "s/.*<latest>\([^<]*\)<\/latest>.*/\1/") | |
jar="" | |
if [ -z "${classifier}" ]; then | |
jar=$artifact-$version.jar | |
else | |
jar=$artifact-$version-$classifier.jar | |
fi | |
url=$repopath/$version/$jar | |
# Download | |
# echo $url | |
curl $url |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment