I wanted to know if we can have mass upload of artifacts to the repository in Nexus.
Nexus supports Mass upload of artifacts?
See this answer for a Groovy script that achieves the same thing but using the standard deployment process: #3240977 –
Volsci
You can do it in a variety of ways:
- Use the Nexus artifact upload page (note this only works for multiple artifacts with the same groupId and artifactId).
- Set up a script, with multiple invocations of the maven-deploy-plugin's deploy-file goal, one for each artifact.
- If you have access to the file system, you can copy the files directly into [sonatype-work]/storage/[repository-name]. If you do this, set up scheduled tasks to rebuild the metadata and reindex the repository.
in the latest version of nexus rebuilding the metadata is just right click on the repository in nexus –
Polik
I would not consider the nexus upload page useful for mass upload of artifacts since the file dialog it pops-up only allows a single selection - so every artifact requires multiple button clicks which gets old very quickly. –
Maxiemaxilla
Third option worked like a champ, needed to click refresh a few times for it to pick up the changes on disk though. Just copy everything under the .../.m2/repository directory in the .../sonatype_work/nexus/storage/thirdparty directory. –
Bounteous
@Bounteous I have nexus-3.12.1-01. I am not able to find storage folder. –
Druggist
This will not work for Nexus 3 and above. The local storage is not in the form of plain binary files anymore; everything is stored as 'blobs'. –
Simms
Use the Nexus Repository Conversion Tool to create Release and Snapshot folders based on your local .m2 folder and then move the contents of those folders into [sonatype-work]/storage/[repository-name].
That link appears to be dead or to now require a login. This question has some information on how to use the tool, though: #4243977 –
Ommiad
Use my script to begin with
#!/bin/bash
# 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
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'
© 2022 - 2024 — McMap. All rights reserved.