---
url: /en/artifact/generic.md
description: >
  Instructions for using the Generic Artifact Registry in CNB, including pushing
  and pulling artifacts via command line, Cloud Native Build pipelines, and
  Workspaces, with package naming rules.
---
## Prerequisites

1. [Create Artifact Registry](/en/artifact/intro.md#create-artifact-registry)
2. [Get Artifact Registry Address](/en/artifact/intro.md#get-artifact-registry-address)
3. [Create Token](/en/artifact/intro.md#create-access-token)

## Push Artifacts

::: tip Credential Setup
Before pushing or pulling artifacts, configure `.netrc` authentication credentials (one-time setup):

```shell

printf "machine generic.cnbprod.alpha.qq.com\nlogin cnb\npassword %s\n" "${CNB_TOKEN}" > ~/.netrc
```

For how to obtain `CNB_TOKEN`, refer to [Creating an Access Token](./intro.md#creating-an-access-token).
:::

### Local Command Line Push

After configuring credentials, run the following command to push artifacts
(replace `<REPO_URL>`, `<PACKAGE>`, `<VERSION>`, `<LOCAL_FILE_NAME>` with actual values):

```shell
curl --netrc '<REPO_URL>/<PACKAGE>?version=<VERSION>' -T '<LOCAL_FILE_NAME>'
```

### Push in Cloud Native Build

1. Add the following content to `.cnb.yml` and commit to your repository. Push a Tag to trigger the build; the Tag value will be used as the artifact version:

```yaml title=".cnb.yml"
$:
  tag_push:
    - docker:
        image: curlimages/curl
      stages:
        - name: setup netrc
          script: printf "machine generic.cnbprod.alpha.qq.com\nlogin cnb\npassword %s\n" "${CNB_TOKEN}" > ~/.netrc
        - name: upload
          script: curl --netrc "<REPO_URL>/<PACKAGE>?version=${CNB_BRANCH}" -T "<LOCAL_FILE_NAME>"
```

> Replace `<REPO_URL>`, `<PACKAGE>`, `<LOCAL_FILE_NAME>` with actual values. It is recommended to use [Semantic Versioning](https://semver.org/).

### Push in Workspaces

1. Click the **"Workspaces"** button in the upper right corner of the repository page to enter the development environment
2. After configuring credentials, run the push command (same as [Local Command Line Push](#local-command-line-push)):

```shell
curl --netrc '<REPO_URL>/<PACKAGE>?version=<VERSION>' -T '<LOCAL_FILE_NAME>'
```

## Use Artifacts

### Pull Artifacts

If `.netrc` credentials are already configured (see tip in Push Artifacts section above), pull directly:

```shell
curl -OfL --netrc '<REPO_URL>/<PACKAGE>?version=<VERSION>'
```

(replace `<REPO_URL>`, `<PACKAGE>`, `<VERSION>` with actual values)

### Delete Artifacts

Generic artifact registry does not support command-line deletion yet.
Please refer to [Delete Artifacts](/en/artifact/intro.md#delete-artifacts).

## FAQ

### Q1: Package Name Restriction Rules

> Package name refers to the full path, for example `a/b/c.txt`.

1. Maximum length is 128 characters, with a maximum depth of 5 levels
2. Case-sensitive: `a/b/c.txt` and `A/B/C.TXT` are different paths
3. Directory and file cannot share the same name: `a/b/c` and `a/b/c/` cannot coexist
4. Path segments cannot start or end with spaces
5. A single `-` cannot be used as a directory or file name
6. Package name characters must match the regex: `^[a-zA-Z0-9\u4e00-\u9fa5._\\-/ ]+$`
