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:
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.
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.
Push artifacts. In your Jenkins pipeline, declare the
harnessClitool and use thehcbuild step (or ashstep) to run CLI commands such ashc 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
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
hcin 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
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?