Upload artifacts to Sonatype Nexus
You can use Harness CI to upload artifacts to Sonatype Nexus Repository Manager.
You can use the Nexus Publish plugin in your CI pipelines to upload artifacts to Sonatype Nexus Repository Manager.
You need:
Access to a Sonatype Nexus Repository Manager instance.
A CI pipeline with a Build stage.
Steps in your pipeline that generate artifacts to upload, such as by running tests or building code. The steps you use depend on what artifacts you ultimately want to upload.
You can also upload artifacts to S3, upload artifacts to GCS, and upload artifacts to JFrog. For other upload locations, you can use a script in a Run step.
Use the Nexus Publish plugin
In your CI pipeline's Build stage, add a Plugin step.
Enter a Name and optional Description.
For Container Registry, select a Docker connector.
In the Image field, enter
harnesscommunity/publish-nexus-repository:1.1.1.Under Optional Configuration, add Settings to configure the Nexus Publisher plugin's properties as described in the following table.
username
String
A username for accessing Nexus Repository Manager.
admintest-user
password
String
An expression referencing a secret containing the password for the specified username.
<+secrets.getValue("nexus_password")>
server_url
Public URL
The URL of your Nexus Repository Manager instance.
http://11.222.333.444:8000/
filename
String
The path to the target artifact that you want to upload.
./target/example-1.0.jar
format
String
The repository format.
maven2raw
repository
String
The name of the repository where you want to upload the artifact.
maven-releases
attributes
String of key-value pairs
Component and asset attributes providing additional artifact metadata.
Do not add double quotes (") to this value.
-CgroupId=org.dronetest -CartifactId=example -Cversion=1.0 -Aextension=jar -Aclassifier=bin

The following YAML example describes a Plugin step in a CI stage that uploads an artifact to Sonatype Nexus.
Plugin step specifications
type: Pluginname:Specify a step name.identifier:Specify a unique step ID.connectorRef:Specify a Docker connector.image: harnesscommunity/publish-nexus-repository:1.1.1settings:Configure the Nexus Publisher plugin's properties as described in the following table.
username
String
A username for accessing Nexus Repository Manager.
admintest-user
password
String
An expression referencing a secret containing the password for the specified username.
<+secrets.getValue("nexus_password")>
server_url
Public URL
The URL of your Nexus Repository Manager instance.
http://11.222.333.444:8000/
filename
String
The path to the target artifact that you want to upload.
./target/example-1.0.jar
format
String
The repository format.
maven2raw
repository
String
The name of the repository where you want to upload the artifact.
maven-releases
attributes
String of key-value pairs
Component and asset attributes providing additional artifact metadata.
"-CgroupId=org.dronetest -CartifactId=example -Cversion=1.0 -Aextension=jar -Aclassifier=bin"
View artifacts on the Artifacts tab
You can use the Artifact Metadata Publisher plugin to publish artifact URLs on the Artifacts tab.
To learn more on how to publish artifacts to the tab, go to Publish anything to the artifacts tab.
This makes it easier to find artifacts associated with specific builds. To do this, add another Plugin step after the Nexus Publisher plugin step.
Configure the Plugin step to use the Artifact Metadata Publisher plugin:
Name: Enter a name.
Container Registry: Select a Docker connector.
Image: Enter
plugins/artifact-metadata-publisher.Settings: Add the following two settings as key-value pairs.
file_urls: The URL to the artifact that was uploaded by the Nexus Publisher plugin. If you uploaded multiple artifacts, you can provide a list of URLs.artifact_file: Provide any.txtfile name, such asartifact.txtorurl.txt. This is a required setting that Harness uses to store the artifact URL and display it on the Artifacts tab. This value is not the name of your uploaded artifact, and it has no relationship to the artifact object itself.
Add a Plugin step that uses the artifact-metadata-publisher plugin.
connectorRef: Use the built-in Docker connector (account.harness.Image) or specify your own Docker connector.image: Must beplugins/artifact-metadata-publisher.file_urls: Provide the URL to the artifact that was uploaded by the Nexus Publisher plugin. If you uploaded multiple artifacts, you can provide a list of URLs.artifact_file: Provide any.txtfile name, such asartifact.txtorurl.txt. This is a required setting that Harness uses to store the artifact URL and display it on the Artifacts tab. This value is not the name of your uploaded artifact, and it has no relationship to the artifact object itself.
Build logs and artifact files
When you run the pipeline, you can observe the step logs on the build details page.
If the Nexus Publisher plugin step succeeds, you can find the artifact in your Sonatype Nexus repo. You can use the Artifact Metadata Publisher plugin to view artifacts on the Artifacts tab.
Pipeline YAML example
This example pipeline has steps that build an artifact, upload it to a Sonatype Nexus repo, and then use the Artifact Metadata Publisher plugin to show a link to the artifact on the Artifacts tab.
Troubleshoot uploading artifacts
Go to the CI Knowledge Base for questions and issues related uploading artifacts, such as:
Last updated
Was this helpful?
