-
-
Save SanSan-/3acc532687df60cfcc037cc79baedd92 to your computer and use it in GitHub Desktop.
#!/bin/bash | |
files="./files.out" | |
releasefiles="./release.out" | |
snapshotfiles="./snapshot.out" | |
username="admin" | |
password="admin123" | |
nexusurl="http://nexus/content/repositories/thirdparty/" | |
snapshoturl="http://nexus/content/repositories/Snapshots/" | |
releaseurl="http://nexus/content/repositories/Releases/" | |
find . -name '*.*' -type f | cut -c 3- | grep "/" > $files | |
find . -name '*.*' -type f | cut -c 3- | grep "SNAPSHOT" | grep "/" > $snapshotfiles | |
find . -name '*.*' -type f | cut -c 3- | grep -v "SNAPSHOT" | grep "/" > $releasefiles | |
# while read i; do | |
# echo "upload $i to $nexusurl" | |
# curl -v -u $username:$password --upload-file $i "$nexusurl$i" | |
# done <$files | |
while read i; do | |
echo "upload $i to $snapshoturl" | |
curl -v -u $username:$password --upload-file $i "$snapshoturl$i" | |
done <$snapshotfiles | |
while read i; do | |
echo "upload $i to $releaseurl" | |
curl -v -u $username:$password --upload-file $i "$releaseurl$i" | |
done <$releasefiles |
@yottta I'm glad that it helped to you.
Quite useful, congrats!
Still works like a charm on our Nexus 2 repository. Great time saver, thanks!
I did another one in python after the inspiration from you 😄
I hope it works for you
https://gist.github.com/m-serag-lab/adf41e89e967646b22047bfe2145ab14
Just in case someone ist stumbeling over this thread. I found my setup more suitable:
this script needs a "artifacts" file right next to it. Create it by using following script in your .m2-folder
find -iname "*.pom" -printf "%h\n" > files; find -iname "*.jar" -printf "%h\n" >> files; cat files | sort | uniq -u > artifacts; rm files
Then use following script to upload the collected artifacts:
NEXUS_USERNAME="admin"
NEXUS_PASSWORD="nexus"
NEXUS_URL="localhost:8081"
cat artifacts | while read i; do
pompath=$(find $i -name *.pom)
jarpath=$(find $i -name *.jar)
# extracting metainformations from pom
groupId=$(echo $pompath | xargs xpath -e 'project/groupId/text()')
artifactId=$(echo $pompath | xargs xpath -e 'project/artifactId/text()')
version=$(echo $pompath | xargs xpath -e 'project/version/text()')
if test -z "$groupId"
then
echo "project-groupId is empty - using parent/groupId"
groupId=$(echo $pompath | xargs xpath -e 'project/parent/groupId/text()')
fi
if test -z "$version"
then
echo "project-version of jar-pom is empty - using parent/version"
version=$(echo $pompath | xargs xpath -e 'project/parent/version/text()')
fi
# choosing upload-strategy, preferring jar-upload
if test -z "$jarpath"
then
echo "uploading $artifactId as pom"
# a 400 error means that the artifactId already exists
mvn deploy:deploy-file \
-DgroupId=$groupId \
-DartifactId=$artifactId \
-Dversion=$version \
-Dpackaging=pom \
-Dfile=$pompath \
-Durl="http://${NEXUS_USERNAME}:${NEXUS_PASSWORD}@${NEXUS_URL}/repository/maven-releases/"
echo "uploading $pompath with groupId: $groupId; artifactId: $artifactId; version: $version"
else
echo "uploading $artifactId as jar"
# a 400 error means that the artifactId already exists
mvn deploy:deploy-file \
-DgroupId=$groupId \
-DartifactId=$artifactId \
-Dversion=$version \
-Dpackaging=jar \
-DgeneratePom=true \
-Dfile=$jarpath \
-Durl="http://${NEXUS_USERNAME}:${NEXUS_PASSWORD}@${NEXUS_URL}/repository/maven-releases"
echo "uploading $jarpath with groupId: $groupId; artifactId: $artifactId; version: $version"
fi
done
echo 'done uploading artifacts'
Thanks all and in particular kschuemann.
I found kschuemann's script really useful for this but I had to adapt it to upload a load of thrid party packages, please see nrxm
Thanks for the initial draft!
For nexus 3.x I used this instead: