How can I programmatically upload files into Nexus 3?

There are may ways to upload artifacts into Nexus 3 without running a build. (See this article for Nexus 2)

Direct Upload using HTTP POST to Components REST API

A generic component upload REST API is available as of version 3.9.0.

Nexus 3.9.0 to 3.13.0 - POST /service/rest/beta/components
Nexus 3.13.0 and newer - POST /service/rest/v1/components

Information and examples at our help site.

Direct Upload using HTTP PUT to the Repository Path

Some repository formats such as Maven 2, YUM, and RAW allow direct upload of assets using HTTP PUT. Formats such as NuGet, NPM, and Docker DO NOT support these type of simple HTTP PUT uploads.

You can do an HTTP PUT of local file to a repository path using the form /repository/<repo-id>/<path-of-file>

A curl example:

curl -v -u admin:admin123 --upload-file pom.xml http://localhost:8081/repository/maven-releases/org/foo/1.0/foo-1.0.pom

Use a Format Specific Client

Each repository format has specific client side tools that are used to interact with a repository. Your first choice when uploading files to a repository manager is use an official client by consulting their documentation.

Example Client Tools that can deploy files by Repository Format - we do not claim this list to be exhaustive:

Repository Format Tools
Maven 2

Apache Maven 2
Apache Ant
Gradle

Docker Docker CLI
PyPI twine
NuGet NuGet CLI
npm npm CLI
Rubygems gem CLI

Maven 2 maven-deploy-plugin:deploy-file Goal

You can deploy files using the "deploy-file" goal on the Maven deploy plugin

Example without a pom file:

mvn deploy:deploy-file -DgroupId=com.somecompany -DartifactId=project -Dversion=1.0.0 -DgeneratePom=true -Dpackaging=jar -DrepositoryId=nexus -Durl=http://localhost:8081/repository/maven-releases -Dfile=target/project-1.0.0.jar

With a pom file:

mvn deploy:deploy-file -DgeneratePom=false -DrepositoryId=nexus -Durl=http://localhost:8081/repository/maven-releases -DpomFile=pom.xml -Dfile=target/project-1.0.0.jar

This plugin goal also allows deployment of snapshot versions, and the plugin will take care of calculating the timestamped version needed:

mvn deploy:deploy-file -DgroupId=com.somecompany -DartifactId=project -Dversion=1.0.0-SNAPSHOT -DgeneratePom=true -Dpackaging=jar -DrepositoryId=nexus -Durl=http://localhost:8081/repository/maven-snapshots -Dfile=target/project-1.0.0-SNAPSHOT.jar

Note: The "repositoryId" property value is not a Nexus repository ID. it is the <id> element value of a <server> section in your settings.xml file which has the credentials needed for deployment. If these credentials are not configured you will see an error like: "Return code is: 401, ReasonPhrase: Unauthorized."

<servers>
...
  <server>
      <id>nexus</id>
      <username>deployment</username>
      <password>deployment123</password>
    </server>
  </servers>

Maven 2 wagon-maven-plugin:upload-single Goal

You can deploy files using the "upload-single" goal on the Maven Wagon plugin. This approach is useful when deploying adhoc files to a "raw" repository.

mvn wagon:upload-single -Dwagon.serverId=nexus -Dwagon.url=http://localhost:8081/repository/raw-hosted/ -Dwagon.fromFile=fileToUpload.txt

Note: The "wagon.serverId" property value is not a Nexus repository ID. It is the <id> element value of a <server> section in your settings.xml file which has the credentials needed for deployment. If these credentials are not configured you will see an error like: "Return code is: 401, ReasonPhrase: Unauthorized."

Have more questions? Submit a request

0 Comments

Article is closed for comments.
Powered by Zendesk