Downloading artifacts through SSH or similar


#1

I currently have a shell script which you can see below that downloads the latest artifact from my Nexus repo. I was wondering if there is a way to download the artifact without using username/password. For example with SSH, or a certificate or something else?

#!/bin/sh

groupId="myGroup"
artifactId="test-app"
version="1.0-SNAPSHOT"
nexusUser="admin"

classifier=""
type="jar"
repo="test-app"                                                                                                                                                                                                                              
# Nexus 3
base="http://192.168.56.2:8081/repository/${repo}"

if [[ $classifier != "" ]]; then
classifier="-${classifier}"
fi

# Read Password
echo -n Please enter password for user ${nexusUser}:
read -s password
echo
password=$password

filename="${artifactId}-${version}${classifier}.${type}"

if [[ "${version}" == "LATEST" || "${version}" == *SNAPSHOT* ]] ; then
if [[ "${version}" == "LATEST" ]] ; then
version=$(xmllint --xpath "string(//latest)" <(curl -s "${base}/${groupIdUrl}/${artifactId}/maven-metadata.xml"))
fi
timestamp=`curl -u ${nexusUser}:${password} -s "${base}/${groupId}/${artifactId}/${version}/maven-metadata.xml" | xmllint --xpath "string(//timestamp)" -`
buildnumber=`curl -u ${nexusUser}:${password} -s "${base}/${groupId}/${artifactId}/${version}/maven-metadata.xml" | xmllint --xpath "string(//buildNumber)" -`
wget --user ${nexusUser} --password ${password} -P /nexus/artifacts "${base}/${groupId}/${artifactId}/${version}/${artifactId}-${version%- 
SNAPSHOT}-${timestamp}-${buildnumber}.${type}"
 else
wget --user ${nexusUser} --password ${password} -P /nexus/artifacts "${base}/${groupId}/${artifactId}/${version}/${artifactId}-${version}${classifier}.${type}"                                                                            
fi

#2

If you are a Nexus 3 Pro user you should consider using the User Token feature. Security Setup with User Tokens