---
url: /en/artifact/ohpm.md
---
## Prerequisites

1. [Create Artifact Registry](./intro.md#creating-an-artifact-registry)
2. [Obtain Artifact Registry Address](./intro.md#obtaining-the-artifact-registry-address)
3. [Create Access Token](./intro.md#creating-an-access-token)

## Local Usage

### Configure Credentials

Two methods are provided:
::: tabs
@tab Command-line setup
Replace `<YOUR_TOKEN>` with your token, `<REPO_URL>` with the Artifact Registry address, and `<REPO_URL_SUFFIX>` with the Artifact Registry address without the protocol prefix.

```bash
# Example
# ohpm config set registry https://ohpm.cnb.share.ralphlauren.cn/cnb/ohpm-repo/-/packages/
# ohpm config set publish_registry https://ohpm.cnb.share.ralphlauren.cn/cnb/ohpm-repo/-/packages/
# ohpm config set //ohpm.cnb.share.ralphlauren.cn/cnb/ohpm-repo/-/packages/:_auth=<YOUR_TOKEN>

# Configure pull repository
ohpm config set registry <REPO_URL>
# Configure push repository
ohpm config set publish_registry <REPO_URL>

ohpm config set //<REPO_URL_SUFFIX>:_auth=<YOUR_TOKEN>
```

@tab Configuration file setup
Paste the following content into the .ohpmrc file in the same directory as package.json.

Replace `<YOUR_TOKEN>` with your token, `<REPO_URL>` with the Artifact Registry address, and `<REPO_URL_SUFFIX>` with the Artifact Registry address without the protocol prefix.

```ini
# Example
# registry=https://ohpm.cnb.share.ralphlauren.cn/cnb/ohpm-repo/-/packages/
# publish_registry=https://ohpm.cnb.share.ralphlauren.cn/cnb/ohpm-repo/-/packages/
# //ohpm.cnb.share.ralphlauren.cn/cnb/ohpm-repo/-/packages/:_auth=<YOUR_TOKEN>

# Configure pull repository
registry=<REPO_URL>
# Configure push repository
publish_registry=<REPO_URL>

//<REPO_URL_SUFFIX>:_auth=<YOUR_TOKEN>
```

:::

### Pull Artifacts

Use the following command to pull artifacts. Replace `<PACKAGE_NAME>`, `<VERSION>`, and `<REPO_URL>`.

```bash
# ohpm install @pura/harmony-utils@1.3.6 --registry=https://ohpm.cnb.share.ralphlauren.cn/cnb/ohpm-repo/-/packages/

ohpm install <PACKAGE_NAME>@<VERSION> --registry=<REPO_URL>
```

### Push Artifacts

1. Initialize oh-package.json5. Replace `<PACKAGE_NAME>` and `<VERSION>`.

```json
{
  "name": "<PACKAGE_NAME>",
  "version": "<VERSION>",
  "description": "",
  "main": "index.js",
  "author": "",
  "license": "MIT"
}
```

2. Use the following command to publish the ohpm package. Replace `<HAR_OR_TGZ_FILE>` with the package file path and `<REPO_URL>` with the Artifact Registry address.

```bash
# Example
# ohpm publish library.har --publish_registry=https://ohpm.cnb.share.ralphlauren.cn/cnb/ohpm-repo/-/packages/

ohpm publish <HAR_OR_TGZ_FILE>  --publish_registry=<REPO_URL>
```

## Cloud Native Build

### Configure Credentials

Cloud Native Build supports three ways to use tokens. Refer to [Using Tokens in Cloud Native Build and Development](./intro.md#using-tokens-in-workspaces-and-cloud-native-build). Below are the specific client usage methods:

Two methods are provided:
::: tabs
@tab Command-line setup
Replace `<REPO_URL>` with the Artifact Registry address and `<REPO_URL_SUFFIX>` with the Artifact Registry address without the protocol prefix.

```bash
# Example
# ohpm config set registry https://ohpm.cnb.share.ralphlauren.cn/cnb/ohpm-repo/-/packages/
# ohpm config set publish_registry https://ohpm.cnb.share.ralphlauren.cn/cnb/ohpm-repo/-/packages/
# ohpm config set //ohpm.cnb.share.ralphlauren.cn/cnb/ohpm-repo/-/packages/:_auth=${CNB_TOKEN}

# Configure pull repository
ohpm config set registry <REPO_URL>
# Configure push repository
ohpm config set publish_registry <REPO_URL>

# Method 1: Use built-in environment variable CNB_TOKEN
ohpm config set //<REPO_URL_SUFFIX>:_auth=${CNB_TOKEN}

# Method 2: Directly use, replace <YOUR_TOKEN> with your token
# ohpm config set //<REPO_URL_SUFFIX>:_auth=<YOUR_TOKEN>

# Method 3: Secret Registry, replace <ENV_NAME> with your secret registry variable
# ohpm config set //<REPO_URL_SUFFIX>:_auth=${<ENV_NAME>}
```

@tab Configuration file setup
Paste the following content into the .ohpmrc file. Replace `<REPO_URL>` with the Artifact Registry address and `<REPO_URL_SUFFIX>` with the Artifact Registry address without the protocol prefix.

```ini
# Example
# registry=https://ohpm.cnb.share.ralphlauren.cn/cnb/ohpm-repo/-/packages/
# publish_registry=https://ohpm.cnb.share.ralphlauren.cn/cnb/ohpm-repo/-/packages/
# //ohpm.cnb.share.ralphlauren.cn/cnb/ohpm-repo/-/packages/:_auth=<YOUR_TOKEN>

# Configure pull repository
registry=<REPO_URL>
# Configure push repository
publish_registry=<REPO_URL>

# Method 1: Use built-in environment variable CNB_TOKEN
//<REPO_URL_SUFFIX>:_auth=${CNB_TOKEN}

# Method 2: Directly use, replace <YOUR_TOKEN> with your token
# //<REPO_URL_SUFFIX>:_auth=<YOUR_TOKEN>

# Method 3: Secret Registry, replace <ENV_NAME> with your secret registry variable
# //<REPO_URL_SUFFIX>:_auth=${<ENV_NAME>}
```

:::

### Pull Artifacts

Replace `<PACKAGE_NAME>`, `<VERSION>`, `<REPO_URL>` with the Artifact Registry address, and `<REPO_URL_SUFFIX>` with the Artifact Registry address without the protocol prefix.

```yaml title=".cnb.yml"
main:
  push:
    - docker:
        image: <ohpm_image> # Use your own ohpm image
      stages:
        - name: ohpm install
          script:
            # If using command-line setup, include the following two lines. Not needed for configuration file setup.
            - ohpm config set registry <REPO_URL>      
            - ohpm config set //<REPO_URL_SUFFIX>:_auth=${CNB_TOKEN}

            - ohpm install <PACKAGE_NAME>@<VERSION> --registry=<REPO_URL>
```

### Push Artifacts

Replace `<HAR_OR_TGZ_FILE>` with the package file path, `<REPO_URL>` with the Artifact Registry address, and `<REPO_URL_SUFFIX>` with the Artifact Registry address without the protocol prefix.

```yaml title=".cnb.yml"
main:
  push:
    - docker:
        image: <ohpm_image> # Use your own ohpm image
      stages:
        - name: ohpm publish
          script:
            # If using command-line setup, include the following two lines. Not needed for configuration file setup.
            - ohpm config set publish_registry <REPO_URL>      
            - ohpm config set //<REPO_URL_SUFFIX>:_auth=${CNB_TOKEN}

            - ohpm publish <HAR_OR_TGZ_FILE> --publish_registry=<REPO_URL>
```

## Workspaces

### Configure Credentials

Same as [Cloud Native Build Configure Credentials](./ohpm.md#configure-credentials-1)

### Configure Development Image

```yaml title=".cnb.yml"
$:
  vscode:
    - docker:
        image: <ohpm_image> # Use your own ohpm image
```

### Pull Artifacts

Same as [Local Development Pull Artifacts](./ohpm.md#pull-artifacts)

### Push Artifacts

Same as [Local Development Push Artifacts](./ohpm.md#push-artifacts)

## More Usage

For more ohpm usage, refer to the official ohpm documentation.
