Skip to content

Migrate from Sonatype Nexus Repository

This page moves the files in your Nexus Repository 3 repositories to CloudRepo and repoints your builds, with Nexus left running until your builds pass against CloudRepo. It copies files and nothing else: your users, permissions and every other piece of data that is not a file stay in Nexus. For hosted Maven, PyPI and Docker repositories (Docker from version 0.6.0), one command does steps 3 and 4 and checks every file: every Maven file, every wheel and sdist of a PyPI repository, every tag of a Docker repository, and every version of each npm package with its dist-tags.

  1. List what you have and decide where each repository goes.
  2. Create the repositories in CloudRepo.
  3. Export the files from Nexus.
  4. Import them into CloudRepo.
  5. Repoint your builds.
  6. Check, then cut over.

You need a CloudRepo organization. No account yet? Start free trial. 14 days free. No credit card required.

Used on this page only, never saved. Never enter a token or password here.

List your repositories with the Nexus REST API. It returns the repositories your authenticated user has browse permission to access. Pass curl a Nexus user credential that can read them through a netrc file, as in step 3.

Terminal
curl --netrc-file ~/.nexus.netrc --silent --fail \
"https://nexus.example.com/service/rest/v1/repositories" | jq -r '.[] | [.name, .format, .type] | @tsv'

Then decide where each one goes. The left column uses the format and type names that Sonatype’s repositories API returns:

In Nexus In CloudRepo
Hosted repository, format maven2, npm, pypi or docker A repository of that format. Its files are what you export and import.
Proxy repository A proxy repository, if the upstream is one CloudRepo offers. Nothing to export: a proxy fills itself from the upstream.
Group repository No copy. Sonatype describes a repository group as the aggregated content of multiple proxy and hosted repositories under one URL, so you move those. Point builds at the CloudRepo repositories directly. For Maven, Docker, PyPI, npm and Go (PyPI, npm and Go in early access), a group repository can serve several repositories under one address.
Hosted repository, format raw A Maven repository: CloudRepo has no raw type, and a Maven repository serves any file at any path. From version 0.8.0, cloudrepo-migrate nexus3 moves it into one when --repo names it, every file at the same path.
Proxy repository, format go or yum A Go or yum proxy repository, in early access, if the upstream is one CloudRepo offers.
Any other format No CloudRepo repository for it. CloudRepo hosts Maven, Python, npm and Docker, and proxies Go and yum in early access.

This page covers Nexus Repository 3, whose REST API the commands use. For its hosted Maven, PyPI and Docker repositories (Docker from version 0.6.0), and for its hosted npm repositories every version of each package with its dist-tags, one command moves them. For Nexus 2, one command moves the hosted Maven repositories and every version of each npm package with its dist-tags. For another Nexus version, export the files by any means that keeps each repository’s directory layout, then continue at step 4. Leaving JFrog Artifactory? One command moves its local Maven repositories.

For each hosted repository, create a repository of the same format in CloudRepo. Give it the name your builds already use if you can, so a URL only changes in one place. See Creating a repository. Then add users who need access. Create a repository token with Download and publish packages for the import, and Download packages tokens for builds that only pull. Nexus roles do not copy: you set each user’s access when you add them to CloudRepo.

Give your Nexus credential to curl through a netrc file, so it is on no command line.

~/.nexus.netrc
machine nexus.example.com
login nexus-user
password NEXUS_PASSWORD

Keep the file readable by you alone (chmod 600 ~/.nexus.netrc). Then, for each hosted repository, page through its assets with the assets API and download each one into a directory named for the repository. Per Sonatype’s pagination page, each response includes a continuationToken while more items remain; pass it back as continuationToken= on the same query for the next page, and stop when the token is null:

Terminal
HOST=https://nexus.example.com
REPO=maven-releases
(
NEXT=""
: > "$REPO.txt"
while :; do
more=()
[ -n "$NEXT" ] && more=(--data-urlencode "continuationToken=$NEXT")
page=$(curl --netrc-file ~/.nexus.netrc --silent --show-error --fail --get --data-urlencode "repository=$REPO" \
"${more[@]}" "$HOST/service/rest/v1/assets") \
|| { echo "FAILED: could not list $REPO" >&2; exit 1; }
printf '%s' "$page" | jq -r '.items[] | [.path, .downloadUrl] | @tsv' >> "$REPO.txt" \
|| { echo "FAILED: could not read the list of $REPO" >&2; exit 1; }
NEXT=$(printf '%s' "$page" | jq -r '.continuationToken // empty')
[ -n "$NEXT" ] || break
done
: > "$REPO.failed.txt"
failed=0
while IFS=$'\t' read -r asset_path url; do
curl --netrc-file ~/.nexus.netrc --silent --show-error --fail --create-dirs \
--output "export/$REPO/$asset_path" "$url" \
|| { echo "FAILED: $asset_path" >&2; echo "$asset_path" >> "$REPO.failed.txt"; rm -f "export/$REPO/$asset_path"; failed=$((failed + 1)); }
done < "$REPO.txt"
total=$(wc -l < "$REPO.txt" | tr -d ' ')
if [ "$failed" -gt 0 ]; then
echo "$failed of $total assets could not be fetched; their paths are in $REPO.failed.txt" >&2
exit 1
fi
echo "Exported $total assets from $REPO"
)

Expected: export/<repository>/ holds every asset the assets API listed, saved at the path it gives that asset. The loop prints each asset it could not fetch, writes those paths to <repository>.failed.txt, and exits with a non-zero status if any failed or if the list could not be read. For a Maven repository that is the Maven layout CloudRepo takes as it is. The import loops look under ./export for npm tarballs (.tgz), Python wheels (.whl) and source distributions (.tar.gz), wherever they sit.

From version 0.6.0, cloudrepo-migrate nexus3 moves a hosted Docker repository on Nexus 3 to CloudRepo with no export: every tag, its manifest and every layer, as Docker images on its page explains.

  • What moves. Hosted Docker repositories. Every layer is checked against the digest its manifest names and uploaded by that digest. Every manifest is read back from CloudRepo and compared by digest.
  • What is skipped. A Docker proxy repository, as proxy of its remote: create a proxy repository in CloudRepo instead. A Docker group repository, as a group repository: move the repositories it groups.
  • The token. CLOUDREPO_TOKEN must be a CloudRepo repository token with Download and publish packages on the target Docker repository. There is no username to set.

Create the Docker repository in CloudRepo, put the credentials in the environment as NEXUS_USERNAME, NEXUS_PASSWORD and CLOUDREPO_TOKEN, and use your Nexus repository’s name for docker-hosted. A dry run lists what would move and uploads nothing:

Terminal
cloudrepo-migrate nexus3 \
--nexus-url https://nexus.example.com \
--org your-org \
--repo docker-hosted \
--dry-run

When the list looks right, run it for real:

Terminal
cloudrepo-migrate nexus3 \
--nexus-url https://nexus.example.com \
--org your-org \
--repo docker-hosted \
--report-json report.json

If you would rather copy images yourself, list the ones you want to keep as name:tag lines in images.txt. The import then copies each image with the Docker CLI.

Import artifacts into CloudRepo has one loop for each format. Run it for each repository, then check the bytes arrived. You can run a loop again after a failure, and what a second run skips and what it replaces depends on the format: see Running a loop again.

In each build, replace the Nexus URL and credential with the CloudRepo repository’s URL and a repository token. The page for your build tool shows the file to change:

Pull Maven artifacts and Publish Maven artifacts: ~/.m2/settings.xml holds the credential, and pom.xml holds the repository URL.

The username for every client except npm is the email address of the account that created the token, and the password is the token. In CI, store the token in the CI system’s secret store and expose it as an environment variable, as the pages above show; do not write it into a script or a committed file.

A lockfile holds URLs too. Change every Nexus and Artifactory URL in your builds, lockfiles included maps each Nexus URL to its CloudRepo URL, finds every one in your repositories and regenerates package-lock.json, yarn.lock, poetry.lock and uv.lock.

A script can call Nexus too. If one calls the Nexus REST API to fetch the latest version of an artifact or to upload a file, REST calls in your scripts after Nexus or Artifactory shows the call to run against CloudRepo in its place, and the calls that have none.

Do this in order, and leave Nexus running until the last step:

  1. Build against CloudRepo, with Nexus still up. Point one project at CloudRepo and run its full build, then the projects that depend on it. A 401, 403 or 404 has the same causes as when you publish by hand: see “When a Client Answers 401, 403 or 404” on Repository tokens.
  2. Publish one new version to CloudRepo from CI and install it from a second machine.
  3. Switch every build that still names Nexus, and every CI job’s secret, to CloudRepo.
  4. Stop publishing to Nexus. From now on a new version exists in CloudRepo only.
  5. Keep an export of Nexus until you are sure nothing reads it. Step 3 of this page is that export.

Webhooks, if you used any, are not copied. CloudRepo’s are in Webhooks, and Move Artifactory and Nexus webhooks to CloudRepo maps each Nexus event and payload field to them.

If you are stuck, email support@cloudrepo.io with your organization name, the repositories involved, the command you ran and the error it printed.

View as Markdown