Created
January 21, 2020 09:23
-
-
Save axi92/40b3600879f9a89751ec9c8e1f02110f to your computer and use it in GitHub Desktop.
This script uploads a folder with all its files into a sonatype nexus3 repository.
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 | |
# # ./nexus3-uploader.sh username password repo folder | |
url="http://domain.com:8081/nexus/repository/$repository/" | |
if [ $# -eq 0 ]; then | |
# Read Nexus3 Repository | |
echo -n "Nexus3 repository: " | |
read repository | |
# Read folder to upload | |
echo -n "Folder to upload recursive: " | |
read upload_folder | |
# Read Nexus3 Username | |
echo -n "Nexus3 username: " | |
read username | |
# Read Nexus3 Password | |
echo -n "Nexus3 password: " | |
stty -echo | |
printf "Password: " | |
read password | |
stty echo | |
printf "\n" | |
echo | |
else | |
username=$1 | |
password=$2 | |
repository=$3 | |
upload_folder=$4 | |
fi | |
urls="" | |
count=$(find $upload_folder -type f | wc -l); | |
for filename in $(find $upload_folder -type f ); do | |
if curl --output /dev/null --silent --head --fail "${url}${filename}"; then | |
printf "Version already exists on nexus - Skipping! $filename\n" | |
# exit 1; | |
else | |
printf "Filename $filename\n" | |
#printf "Upload for: $(basename "$filename")\n" | |
#extension="${filename##*.}" | |
curl -u $username:$password --upload-file $filename ${url}${filename} | |
#addurl=${url} | |
#urls="$urls\n${addurl}" | |
fi | |
count="$(($count-1))"; | |
echo $count; | |
done | |
#printf "Artifacts: $urls" |
That is true spaces are not handled in that script
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This doesn't work with folder and files with space in there names. As linux and nexus accepts space in the filename.. it is kind of challenging to work with that..