Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.
IntegrationCi CdHc Cli

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 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 (Docker images, 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 (or a sh 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.

  • 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.

  • Jenkins administrator access. You need permission to install plugins and configure global tools in Jenkins.


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.


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.

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.

To review the full list of supported push subcommands, go to CLI reference.


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, pass the --org and --project flags in your hc commands:


Freestyle jobs

The Harness plugin also supports Freestyle jobs. To review Freestyle job configuration and additional examples, go to Harness Jenkins plugin.


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

The hc command is not found during the pipeline run

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.

Authentication fails with a 401 error

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.

Push succeeds but the artifact does not appear in the registry

Confirm that the --org and --project flags in your hc command point to the correct Harness organization and project where the target registry exists. If you omit these flags, the CLI defaults to the account level, and the push may target a different scope than expected.


Next steps

  • To review installation instructions, credential setup, and additional examples for the plugin, go to Harness Jenkins plugin.

  • To manage artifacts and registries from the CLI, go to CLI reference.

  • To configure client-side authentication for specific package types, go to the relevant page under Client setup.

  • To integrate Artifact Registry with GitHub Actions instead of Jenkins, go to GitHub Actions and Harness Artifacts.

Last updated

Was this helpful?