> 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/github-actions.md).

# 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](https://github.com/marketplace/actions/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 (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](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).
* **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.

{% code title=".github/workflows/push-artifact.yml" overflow="wrap" %}

```yaml
name: Build and push to Harness Artifacts

on:
  push:
    branches: [main]

jobs:
  build-and-push:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Build
        run: |
          # Replace with your actual build commands
          tar -czf build.tar.gz src/

      - name: Setup Harness CLI
        uses: harness/setup-harness-cli@v1
        with:
          api-url: ${{ secrets.HARNESS_URL }}
          account: ${{ secrets.HARNESS_ACCOUNT_ID }}
          token: ${{ secrets.HARNESS_PAT_TOKEN }}

      - name: Push artifact
        run: |
          hc artifact push generic my-registry build.tar.gz \
            --name my-app \
            --version ${{ github.sha }}
```

{% endcode %}

### 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:

```yaml
      - name: Setup Harness CLI
        uses: harness/setup-harness-cli@v1
        with:
          api-url: ${{ secrets.HARNESS_URL }}
          account: ${{ secrets.HARNESS_ACCOUNT_ID }}
          token: ${{ secrets.HARNESS_PAT_TOKEN }}
          org: my-org
          project: my-project
```

***

## 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" %}

```bash
hc artifact push generic my-registry build.tar.gz \
  --name my-app \
  --version ${{ github.sha }}
```

{% endtab %}

{% tab title="npm" %}

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

{% endtab %}

{% tab title="Go" %}

```bash
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).

***

## 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

<details>

<summary>The hc command is not found after the setup step</summary>

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.

</details>

<details>

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

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](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>

Confirm that the `--name` and `--version` flags match the expected package name and version in the registry. The `org` and `project` inputs on the setup action 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 inputs, outputs, version pinning, and additional examples for the GitHub Action, go to [Setup Harness CLI](https://github.com/marketplace/actions/setup-harness-cli).
* 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 Artifacts with Jenkins instead of GitHub Actions, go to [Jenkins and Harness Artifacts](https://developer.harness.io/artifact-registry/3.0/platform-integrations/jenkins.md).

{% @harness-feedback/feedback %}
