> 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/artifact-registry/3.0/platform-integrations/jenkins.md).

# Jenkins

Push and manage artifacts in Harness Artifacts from Jenkins jobs, using the Harness Jenkins plugin to install and authenticate the CLI.

You can push and manage artifacts in Harness Artifacts from Jenkins. The [Harness Jenkins plugin](https://plugins.jenkins.io/harness/) installs and authenticates the Harness CLI (`hc`) in your Freestyle jobs and Pipeline (declarative or scripted) jobs. After the plugin runs authentication, `hc` is available on the Jenkins agent and you can run any CLI command, including `hc artifact push`.

This integration is useful when your builds run in Jenkins and you want to store the resulting artifacts (npm packages, Maven JARs, generic binaries, and others) in Harness Artifacts without migrating your build pipelines to another CI platform.

***

## How it works

The integration follows a three-step pattern:

1. **Install the plugin**. Install the Harness plugin from the Jenkins Plugin Manager. The plugin provides a tool installer for the Harness CLI and a build step that authenticates it.
2. **Configure credentials**. Store your Harness API URL and personal access token (PAT) in Jenkins global configuration. The plugin reads these values at runtime to authenticate the CLI on the build agent.
3. **Push artifacts**. In your Jenkins pipeline, declare the `harnessCli` tool and use the `hc` build step to run CLI commands such as `hc artifact push`.

Because the plugin handles CLI installation and authentication, you do not need to manage binary downloads or credential files manually on each Jenkins agent.

***

## Before you begin

* **Harness account with Artifacts enabled**. You need at least one registry created in Harness Artifacts. To create a registry, go to [Create a registry](https://developer.harness.io/artifact-registry/3.0/registries/create-a-registry.md).
* **Personal access token (PAT)**. Generate a PAT in your Harness account with permissions to push artifacts. To understand authentication, go to [Authentication and identity tokens](https://developer.harness.io/artifact-registry/3.0/concepts/authentication-and-identity-tokens.md).
* **Jenkins administrator access**. You need permission to install plugins and configure global tools in Jenkins.
* **Jenkins 2.541.3 or newer**. The plugin does not install on older versions.

***

## Install and configure the plugin

1. **Install the Harness plugin**. In Jenkins, go to **Manage Jenkins** > **Plugins** > **Available plugins**. Search for **Harness** and click **Install**. Restart Jenkins if prompted.
2. **Configure the Harness CLI tool**. Go to **Manage Jenkins** > **Tools** and add a Harness CLI installation. Enter a name for the installation (for example, `harness-cli`). Jenkins uses this name in the `tools` block of your pipeline.
3. **Add Harness credentials**. Go to **Manage Jenkins** > **System** and configure your Harness API URL and personal access token (PAT). Click **Save** to store the credentials.

   To review installation and credential setup details, go to [Harness Jenkins plugin](https://plugins.jenkins.io/harness/).

***

## Push artifacts from a declarative pipeline

After you install and configure the plugin, add the `harnessCli` tool declaration and the `hc` build step to your Jenkinsfile. The following example builds a Java application and pushes the JAR file to a generic registry in Harness Artifacts.

{% code title="Jenkinsfile" overflow="wrap" %}

```groovy
pipeline {
    agent any

    tools {
        harnessCli 'harness-cli'   // matches the name set in Manage Jenkins > Tools
    }

    stages {
        stage('Build') {
            steps {
                sh 'mvn clean package -DskipTests'
            }
        }

        stage('Push to Harness Artifacts') {
            steps {
                hc 'artifact push generic my-registry target/myapp-1.0.jar --name myapp --version 1.0.0'
            }
        }
    }
}
```

{% endcode %}

### Key points about the pipeline

The following list describes the key elements in the example pipeline:

* **`tools { harnessCli 'harness-cli' }`** tells Jenkins to install and configure the Harness CLI on the agent before any stage runs. The string `'harness-cli'` must match the tool name you entered in **Manage Jenkins** > **Tools**.
* **`hc 'artifact push ...'`** is a build step provided by the Harness plugin. It runs the Harness CLI command and inherits the authentication configured in **Manage Jenkins** > **System**.
* You can use `hc` in any stage, not only at the end. For example, you can push intermediate build outputs in one stage and the final artifact in another.

***

## Push different package types

The `hc artifact push` command supports multiple package types. Replace `generic` with the subcommand that matches your artifact format.

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

```groovy
hc 'artifact push generic my-registry target/myapp-1.0.jar --name my-app --version 1.0.0'
```

{% endtab %}

{% tab title="npm" %}

```groovy
hc 'artifact push npm my-npm-registry ./my-package-1.0.0.tgz'
```

{% endtab %}

{% tab title="Python" %}

```groovy
hc 'artifact push python my-python-registry dist/mypackage-1.0.0.tar.gz'
```

{% endtab %}

{% tab title="Go" %}

```groovy
hc 'artifact push go my-go-registry . --version v1.2.3'
```

{% endtab %}
{% endtabs %}

To review the full list of supported push subcommands, go to [CLI reference](https://developer.harness.io/artifact-registry/3.0/reference/cli.md).

***

## Scope the CLI to an organization and project

By default, the CLI operates at the account level. To scope the session to a specific Harness organization and project, set the organization and project once under **Manage Jenkins** > **System** > **Harness CLI Configuration**. The plugin passes these values to `hc auth login`, so you do not need to pass per-command flags.

The organization and project scope authentication only. They do not change where a push lands, because a push goes to the account and registry name you pass to `hc artifact push`:

```groovy
hc 'artifact push generic my-registry target/myapp-1.0.jar --name my-app --version 1.0.0'
```

***

## Freestyle jobs

The Harness plugin also supports Freestyle jobs. To review Freestyle job configuration and additional examples, go to [Harness Jenkins plugin](https://plugins.jenkins.io/harness/).

***

## Security considerations

* **Store credentials in Jenkins**. Never hard-code your PAT or API URL in the Jenkinsfile. Use the plugin's global configuration under **Manage Jenkins** > **System** to store credentials securely.
* **Use least-privilege tokens**. Generate a PAT with only the permissions required to push to the target registry.
* **Restrict plugin configuration access**. Limit who can modify the Harness plugin settings in Jenkins to prevent unauthorized changes to the API URL or token.
* **Use credentials binding for additional secrets**. If your pipeline needs other Harness-related secrets (for example, registry-specific tokens), use the Jenkins Credentials plugin to inject them as environment variables rather than hard-coding them.

***

## Troubleshooting

<details>

<summary>The hc command is not found during the pipeline run</summary>

Verify that the `tools` block in your Jenkinsfile includes `harnessCli` with the correct tool name. The name must match what you configured in **Manage Jenkins** > **Tools**. If the tool is configured but the CLI is still not found, check that the Jenkins agent has internet access to download the CLI binary during the tool installation step.

</details>

<details>

<summary>Authentication fails with a 401 error</summary>

The personal access token configured in **Manage Jenkins** > **System** may be expired or may not have the required permissions. Generate a new PAT in your Harness account and update the token in the Jenkins system configuration. To understand token requirements, go to [Authentication and identity tokens](https://developer.harness.io/artifact-registry/3.0/concepts/authentication-and-identity-tokens.md).

</details>

<details>

<summary>Push succeeds but the artifact does not appear in the registry</summary>

The `org` and `project` configured under **Manage Jenkins** > **System** > **Harness CLI Configuration** do not change where a push lands, because a push goes to the account and registry name. Confirm the registry name passed to `hc artifact push`, and check that you are viewing that registry's organization and project in the Harness UI.

</details>

***

## Next steps

* To review installation instructions, credential setup, and additional examples for the plugin, go to [Harness Jenkins plugin](https://plugins.jenkins.io/harness/).
* To manage artifacts and registries from the CLI, go to [CLI reference](https://developer.harness.io/artifact-registry/3.0/reference/cli.md).
* To configure client-side authentication for specific package types, go to the relevant page under [Client setup](https://developer.harness.io/artifact-registry/3.0/setup/docker.md).
* To integrate Artifact Registry with GitHub Actions instead of Jenkins, go to [GitHub Actions and Harness Artifacts](https://developer.harness.io/artifact-registry/3.0/platform-integrations/github-actions.md).

{% @harness-feedback/feedback %}
