> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/continuous-integration/3.0/use-harness-ci/use-harness-ci/build-and-upload-artifacts/upload-artifacts/upload-artifacts-to-sonatype-nexus.md).

# Upload artifacts to Sonatype Nexus

You can use the [Nexus Publish plugin](https://github.com/harness-community/drone-nexus-publish) in your CI pipelines to upload artifacts to [Sonatype Nexus Repository Manager](https://www.sonatype.com/products/sonatype-nexus-repository).

You need:

* Access to a Sonatype Nexus Repository Manager instance.
* A [CI pipeline](/continuous-integration/use-harness-ci/use-harness-ci/prep-ci-pipeline-components.md) with a [Build stage](/continuous-integration/use-harness-ci/use-harness-ci/set-up-build-infrastructure/ci-stage-settings.md).
* 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](/continuous-integration/use-harness-ci/use-harness-ci/build-and-upload-artifacts/upload-artifacts/upload-artifacts-to-s3.md), [upload artifacts to GCS](/continuous-integration/use-harness-ci/use-harness-ci/build-and-upload-artifacts/upload-artifacts/upload-artifacts-to-gcs-step-settings.md), and [upload artifacts to JFrog](/continuous-integration/use-harness-ci/use-harness-ci/build-and-upload-artifacts/upload-artifacts/upload-artifacts-to-jfrog.md). For other upload locations, you can use a script in a [Run step](/continuous-integration/use-harness-ci/use-harness-ci/run-step-settings.md).

### Use the Nexus Publish plugin <a href="#use-the-nexus-publish-plugin" id="use-the-nexus-publish-plugin"></a>

{% tabs %}
{% tab title="Visual" %}

1. In your CI pipeline's **Build** stage, add a [Plugin step](/continuous-integration/use-harness-ci/use-harness-ci/use-drone-plugins/plugin-step-settings-reference.md).
2. Enter a **Name** and optional **Description**.
3. For **Container Registry**, select a [Docker connector](/harness-ai/use-harness-platform/connectors/cloud-providers/ref-cloud-providers/docker-registry-connector-settings-reference.md).
4. In the **Image** field, enter `harnesscommunity/publish-nexus-repository:1.1.1`.
5. Under **Optional Configuration**, add **Settings** to configure the Nexus Publisher plugin's properties as described in the following table.

| Keys         | Type                      | Description                                                                                                                                                                                                  | Value example                                                                                 |
| ------------ | ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------- |
| `username`   | String                    | A username for accessing Nexus Repository Manager.                                                                                                                                                           | <ul><li><code>admin</code></li><li><code>test-user</code></li></ul>                           |
| `password`   | String                    | An [expression referencing a secret](/harness-ai/use-harness-platform/secrets/add-use-text-secrets.md#step-3-reference-the-encrypted-text-by-identifier) 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.                                                                                                                                                                                       | <ul><li><code>maven2</code></li><li><code>raw</code></li></ul>                                |
| `repository` | String                    | The name of the repository where you want to upload the artifact.                                                                                                                                            | `maven-releases`                                                                              |
| `attributes` | String of key-value pairs | <p>Component and asset attributes providing additional artifact metadata.<br><br>Do not add double quotes (<code>"</code>) to this value.</p>                                                                | `-CgroupId=org.dronetest -CartifactId=example -Cversion=1.0 -Aextension=jar -Aclassifier=bin` |
| {% endtab %} |                           |                                                                                                                                                                                                              |                                                                                               |

{% tab title="YAML" %}
The following YAML example describes a [Plugin step](/continuous-integration/use-harness-ci/use-harness-ci/use-drone-plugins/plugin-step-settings-reference.md) in a `CI` stage that uploads an artifact to Sonatype Nexus.

```yaml
              - step:
                  type: Plugin
                  name: upload_sonatype
                  identifier: upload_sonatype
                  spec:
                    connectorRef: YOUR_IMAGE_REGISTRY_CONNECTOR 
                    image: harnesscommunity/publish-nexus-repository:1.1.1
                    settings:
                      username: deploy-user ## Nexus Repository Manager username
                      password: <+secrets.getValue("nexus_password")> ## Nexus Repository Manager password
                      server_url: http://11.222.333.444:8000/ ## 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 <a href="#plugin-step-specifications" id="plugin-step-specifications"></a>

* `type: Plugin`
* `name:` Specify a step name.
* `identifier:` Specify a unique step ID.
* `connectorRef:` Specify a [Docker connector](/harness-ai/use-harness-platform/connectors/cloud-providers/ref-cloud-providers/docker-registry-connector-settings-reference.md).
* `image: harnesscommunity/publish-nexus-repository:1.1.1`
* `settings:` Configure the Nexus Publisher plugin's properties as described in the following table.

| Keys          | Type                      | Description                                                                                                                                                                                                  | Value example                                                                                   |
| ------------- | ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------- |
| `username`    | String                    | A username for accessing Nexus Repository Manager.                                                                                                                                                           | <ul><li><code>admin</code></li><li><code>test-user</code></li></ul>                             |
| `password`    | String                    | An [expression referencing a secret](/harness-ai/use-harness-platform/secrets/add-use-text-secrets.md#step-3-reference-the-encrypted-text-by-identifier) 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.                                                                                                                                                                                       | <ul><li><code>maven2</code></li><li><code>raw</code></li></ul>                                  |
| `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"` |
| {% endtab %}  |                           |                                                                                                                                                                                                              |                                                                                                 |
| {% endtabs %} |                           |                                                                                                                                                                                                              |                                                                                                 |

{% hint style="info" %}
**TIPS**

You can use variable expressions for **Settings** values. For example, `password: <+stage.variables.nexus_password>` uses a [stage variable](/harness-ai/use-harness-platform/pipelines/add-a-stage.md#stage-variables).

Create [text secrets](/harness-ai/use-harness-platform/secrets/add-use-text-secrets.md) for sensitive information, such as passwords.
{% endhint %}

### View artifacts on the Artifacts tab <a href="#view-artifacts-on-the-artifacts-tab" id="view-artifacts-on-the-artifacts-tab"></a>

You can use the [Artifact Metadata Publisher plugin](https://github.com/drone-plugins/artifact-metadata-publisher) to publish artifact URLs on the [Artifacts tab](/continuous-integration/use-harness-ci/use-harness-ci/viewing-builds.md).

To learn more on how to publish artifacts to the tab, go to [Publish anything to the artifacts tab](/continuous-integration/use-harness-ci/use-harness-ci/build-and-upload-artifacts/artifacts-tab.md).

This makes it easier to find artifacts associated with specific builds. To do this, add another **Plugin** step after the Nexus Publisher plugin step.

{% tabs %}
{% tab title="Visual" %}
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 `.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.
    {% endtab %}

{% tab title="YAML" %}
Add a `Plugin` step that uses the `artifact-metadata-publisher` plugin.

```yaml
               - step:
                  type: Plugin
                  name: publish artifact metadata
                  identifier: publish_artifact_metadata
                  spec:
                    connectorRef: YOUR_IMAGE_REGISTRY_CONNECTOR
                    image: plugins/artifact-metadata-publisher
                    settings:
                      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.
  {% endtab %}
  {% endtabs %}

### Build logs and artifact files <a href="#build-logs-and-artifact-files" id="build-logs-and-artifact-files"></a>

When you run the pipeline, you can observe the step logs on the [build details page](/continuous-integration/use-harness-ci/use-harness-ci/viewing-builds.md).

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](#view-artifacts-on-the-artifacts-tab).

{% hint style="info" %}
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.
{% endhint %}

### Pipeline YAML example <a href="#pipeline-yaml-example" id="pipeline-yaml-example"></a>

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.

```yaml
pipeline:
  name: YOUR_PIPELINE_NAME
  identifier: YOUR_PIPELINE_ID
  projectIdentifier: default
  orgIdentifier: default
  tags: {}
  properties:
    ci:
      codebase:
        connectorRef: YOUR_CODEBASE_CONNECTOR
        repoName: YOUR_CODE_REPO
        build: <+input>
  stages:
    - stage:
        name: stage1
        identifier: stage1
        type: CI
        spec:
          cloneCodebase: true
          execution:
            steps:
              - step:
                  type: Run
                  name: Build
                  identifier: build
                  spec:
                    shell: Sh
                    command: "mvn clean package"
              - step:
                  type: Plugin
                  name: upload_nexus
                  identifier: upload_nexus
                  spec:
                    connectorRef: YOUR_IMAGE_REGISTRY_CONNECTOR
                    image: harnesscommunity/publish-nexus-repository:1.1.1
                    settings:
                      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
                  spec:
                    connectorRef: YOUR_IMAGE_REGISTRY_CONNECTOR
                    image: plugins/artifact-metadata-publisher
                    settings:
                      file_urls: https://repository.sonatype.org/content/sites/...
                      artifact_file: artifact.txt
          platform:
            os: Linux
            arch: Amd64
          runtime:
            type: Cloud
            spec: {}
```

### Troubleshoot uploading artifacts <a href="#troubleshoot-uploading-artifacts" id="troubleshoot-uploading-artifacts"></a>

Go to the [CI Knowledge Base](/continuous-integration/3.0/troubleshooting-and-resources/ci-articles-and-faqs/continuous-integration-faqs.md) for questions and issues related uploading artifacts, such as:

* [Can I send artifacts by email?](/continuous-integration/3.0/troubleshooting-and-resources/ci-articles-and-faqs/continuous-integration-faqs.md#can-i-send-emails-from-ci-pipelines)
* [How do I show content on the Artifacts tab?](/continuous-integration/3.0/troubleshooting-and-resources/ci-articles-and-faqs/continuous-integration-faqs.md#how-do-i-show-content-on-the-artifacts-tab)
