Skip to main content

Upload artifacts to Sonatype Nexus

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

The following YAML example describes a Plugin step in a CI stage that uploads an artifact to Sonatype Nexus.

              - step:
type: Plugin
name: upload_sonatype
identifier: upload_sonatype
connectorRef: account.harnessImage ## Docker Hub container registry connector
image: harnesscommunity/publish-nexus-repository:1.1.1
username: deploy-user ## Nexus Repository Manager username
password: <+secrets.getValue("nexus_password")> ## Nexus Repository Manager password
server_url: ## Nexus Repository instance URL
filename: ./target/example-1.0.jar ## Path to the artifact to upload
format: maven2 ## Repository format
repository: maven-releases ## Destination repository name
attributes: "-CgroupId=org.dronetest -CartifactId=example -Cversion=1.0 -Aextension=jar -Aclassifier=bin" ## Key-value pairs providing additional metadata

Plugin step specifications

  • type: Plugin
  • name: Specify a step name.
  • identifier: Specify a unique step ID.
  • connectorRef: Specify a Docker connector.
  • image: harnesscommunity/publish-nexus-repository:1.1.1
  • settings: Configure the Nexus Publisher plugin's properties as described in the following table.
KeysTypeDescriptionValue example
usernameStringA username for accessing Nexus Repository Manager.
  • admin
  • test-user
passwordStringAn expression referencing a secret containing the password for the specified username.<+secrets.getValue("nexus_password")>
server_urlPublic URLThe URL of your Nexus Repository Manager instance.http://11.222.333.444:8000/
filenameStringThe path to the target artifact that you want to upload../target/example-1.0.jar
formatStringThe repository format.
  • maven2
  • raw
repositoryStringThe name of the repository where you want to upload the artifact.maven-releases
attributesString of key-value pairsComponent and asset attributes providing additional artifact metadata. "-CgroupId=org.dronetest -CartifactId=example -Cversion=1.0 -Aextension=jar -Aclassifier=bin"

You can use variable expressions for Settings values. For example, password: <+stage.variables.nexus_password> uses a stage variable.

Create text secrets for sensitive information, such as passwords.

View artifacts on the Artifacts tab

You can use the Artifact Metadata Publisher plugin to publish artifact URLs on 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.

Add a Plugin step that uses the artifact-metadata-publisher plugin.

               - step:
type: Plugin
name: publish artifact metadata
identifier: publish_artifact_metadata
connectorRef: account.harnessImage
image: plugins/artifact-metadata-publisher
file_urls: https://complete/url/to/artifact/on/nexus
artifact_file: artifact.txt
  • connectorRef: Use the built-in Docker connector (account.harness.Image) or specify your own Docker connector.
  • image: Must be plugins/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 .txt file name, such as artifact.txt or url.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.


On the Artifacts tab, select the step name to expand the list of artifact links associated with that step.

If your pipeline has multiple steps that upload artifacts, use the dropdown menu on the Artifacts tab to switch between lists of artifacts uploaded by different steps.

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.

identifier: YOUR_PIPELINE_ID
projectIdentifier: default
orgIdentifier: default
tags: {}
build: <+input>
- stage:
name: stage1
identifier: stage1
type: CI
cloneCodebase: true
- step:
type: Run
name: Build
identifier: build
shell: Sh
command: "mvn clean package"
- step:
type: Plugin
name: upload_nexus
identifier: upload_nexus
connectorRef: account.harnessImage
image: harnesscommunity/publish-nexus-repository:1.1.1
username: test-user
password: <+secrets.getValue("nexus_password")>
server_url: http://11.222.333.444:8000/
format: maven2
filename: ./target/example-1.0.jar
repository: maven-releases
attributes: "-CgroupId=org.dronetest -CartifactId=example -Cversion=1.0 -Aextension=jar -Aclassifier=bin"
- step:
type: Plugin
name: publish artifact metadata
identifier: publish_artifact_metadata
connectorRef: account.harnessImage
image: plugins/artifact-metadata-publisher
artifact_file: artifact.txt
os: Linux
arch: Amd64
type: Cloud
spec: {}

Troubleshoot uploading artifacts

Go to the CI Knowledge Base for questions and issues related uploading artifacts, such as: