Skip to content

Instantly share code, notes, and snippets.

@DarthHater
Last active July 28, 2021 09:34
Show Gist options
  • Save DarthHater/a4f2738e3bd40d242db22633b59dfd63 to your computer and use it in GitHub Desktop.
Save DarthHater/a4f2738e3bd40d242db22633b59dfd63 to your computer and use it in GitHub Desktop.
Import Nexus Repository 2 Maven, NuGet, npm artifacts into Nexus Repository 3

Nexus Repository Import Script

Wut?

This is a bare bones bash script to import a Nexus 2 Maven, NuGet or npm repository (and likely other file system based repos) into Nexus Repository 3.

Wut does it do?

Imports artifacts into a Nexus Repository 3 Maven2, NuGet or npm hosted repo.

Wut does it not do?

Literally anything else. You want security? Better set it up yourself.

How do I use it?

  • Maven
    • cd rootdirectorywithallyourartifacts
    • ./mavenimport.sh -u admin -p admin123 -r http://localhost:8084/repository/maven-releases/
    • Watch a bunch of verbose output from curl
    • If need be, change -u to user, -p to password, and -r (I bet you'll have to change this) to the repo you want to upload in to
  • NuGet
    • cd rootdirectorywithallyournugetpackages
    • ./nugetimport.sh -k APIKEYFROMNEXUS - r http://localhost:8084/repository/nuget-hosted/
    • Watch the money roll in and the haters start askin
    • You'll need to obtain your APIKEY for Nexus Repository, and obviously set -r to the repo path you want to us
  • npm

Like it?

Great, buy me a beer.

#!/bin/bash
# Get command line params
while getopts ":r:u:p:" opt; do
case $opt in
r) REPO_URL="$OPTARG"
;;
u) USERNAME="$OPTARG"
;;
p) PASSWORD="$OPTARG"
;;
esac
done
find . -type f -not -path '*/\.*' -not -path '*/\^archetype\-catalog\.xml*' -not -path '*/\^maven\-metadata\-local*\.xml' -not -path '*/\^maven\-metadata\-deployment*\.xml' -exec curl -u $USERNAME:$PASSWORD -X PUT -v -T {} $REPO_URL{} \;
#!/bin/bash
# Get command line params
while getopts ":r:k:" opt; do
case $opt in
r) REPO_URL="$OPTARG"
;;
esac
done
find . -type f -not -path '*/\.*' -name '*.tgz' -exec npm publish {} --registry $REPO_URL \;
#!/bin/bash
# Get command line params
while getopts ":r:k:" opt; do
case $opt in
r) REPO_URL="$OPTARG"
;;
k) APIKEY="$OPTARG"
;;
esac
done
find . -type f -not -path '*/\.*' -name '*.nupkg' -exec nuget push {} $APIKEY -Source $REPO_URL \;
@prateekjain-87
Copy link

Hi,
The script is somehow missing empty directories. Can you please suggest how to include the whole directory structure?

@DarthHater
Copy link
Author

It's likely better to use this nowadays: https://github.com/sonatype-nexus-community/nexus-repository-import-scripts

We moved the scripts etc... from this gist over there, better visibility and easier for others to contribute!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment