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

GitHub Actions

Push and manage artifacts in Harness Artifacts directly from GitHub Actions workflows, using the Setup Harness CLI action to install and authenticate.

You can push and manage artifacts in Harness Artifacts from any GitHub Actions workflow. The Setup Harness CLI action installs and authenticates the Harness CLI (hc) in your workflow runner. After the action runs, hc is on PATH and authenticated, so you can run any CLI command, including hc artifact push.

This integration is useful when your builds run in GitHub Actions and you want to store the resulting artifacts (Docker images, npm packages, Maven JARs, generic binaries, and others) in Harness Artifacts without switching to a different CI platform.


How it works

The integration follows a three-step pattern:

  1. Install and authenticate. The harness/setup-harness-cli action downloads the Harness CLI, places it on PATH, and authenticates it with your Harness account using a personal access token (PAT).

  2. Push artifacts. After authentication, you call hc artifact push (or any other hc command) in a subsequent run step to upload build outputs to a registry in Harness Artifacts.

  3. Automatic logout. The action logs the CLI out at the end of the job, even when the job fails, so the personal access token is not left on self-hosted runners.

Because the CLI handles authentication, you do not need to create a Harness connector or manage registry credentials manually in your workflow.


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.

  • GitHub repository secrets. Store the following values as GitHub Actions secrets in your repository or organization settings:

    • HARNESS_URL: Your Harness API URL (for example, https://app.harness.io).

    • HARNESS_ACCOUNT_ID: Your Harness account identifier.

    • HARNESS_PAT_TOKEN: The personal access token you generated.


Set up the GitHub Actions workflow

Add the harness/setup-harness-cli action to your workflow file. The following example checks out the repository, installs and authenticates the Harness CLI, and pushes a generic artifact to a registry.

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 optional org and project inputs on the action:


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.


Security considerations

  • Store credentials as secrets. Never hard-code your PAT, account ID, or API URL in the workflow file. Use GitHub Actions secrets or environment-level secrets.

  • Use least-privilege tokens. Generate a PAT with only the permissions required to push to the target registry.

  • Automatic logout. The setup-harness-cli action runs a post-job cleanup step that logs the CLI out, even when the job fails. This prevents credentials from persisting on self-hosted runners between jobs.

  • Pin the action version. Pin harness/setup-harness-cli to a specific version tag or commit SHA to avoid unexpected changes from upstream updates.


Troubleshooting

The hc command is not found after the setup step

Verify that the harness/setup-harness-cli step completed successfully in the job logs. If the step failed, check that your api-url, account, and token secrets are set correctly in the repository settings. The CLI binary must be on PATH before any subsequent run step can use it.

Authentication fails with a 401 error

The personal access token may be expired or may not have the required permissions. Generate a new PAT in your Harness account and update the HARNESS_PAT_TOKEN secret. To understand token requirements, go to Authentication and identity tokens.

Push succeeds but the artifact does not appear in the registry

Confirm that the --name and --version flags match the expected package name and version in the registry. Also verify that the org and project inputs on the setup action point to the correct Harness organization and project where the target registry exists.


Next steps

  • To review inputs, outputs, version pinning, and additional examples for the GitHub Action, go to Setup Harness CLI.

  • 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 Artifacts with Jenkins instead of GitHub Actions, go to Jenkins and Harness Artifacts.

Last updated

Was this helpful?