Store other formats in Artifact Registry

Learn how to set up an Artifact Registry generic format repository and upload a YAML file.

Before you begin

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Make sure that billing is enabled for your Google Cloud project.

  4. Enable the Artifact Registry API.

    Enable the API

  5. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  6. Make sure that billing is enabled for your Google Cloud project.

  7. Enable the Artifact Registry API.

    Enable the API

Launch Cloud Shell

In the Google Cloud console, activate Cloud Shell.

Activate Cloud Shell

At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.

In this quickstart, you will use Cloud Shell to run gcloud commands.

Create a generic repository

  1. To create a generic format repository named quickstart-generic-repo in the location us-central1 with the description Generic repository, run the following command:

    gcloud artifacts repositories create quickstart-generic-repo \
        --repository-format=generic \
        --location=us-central1 \
        --description="Generic repository"
    
  2. To verify that your repository was created, run the following command:

    gcloud artifacts repositories list
    
  3. To simplify gcloud commands, run the following commands to set the default repository to quickstart-generic-repo and the default location to us-central1.

    1. To set the default repository to quickstart-generic-repo, run the following command:

      gcloud config set artifacts/repository quickstart-generic-repo
      
    2. To set the default location to us-central1, run the following command:

      gcloud config set artifacts/location us-central1
      

    After the values are set, you don't need to specify them in gcloud commands that require a repository or a location.

Upload an artifact to the repository

  1. In your home directory, create a file to upload to your repository:

    echo "hello world" > hello.yaml
    
  2. To upload the file as an artifact to the repository, run the following command:

    gcloud artifacts generic upload \
        --source=hello.yaml \
        --package=my-package \
        --version=1.0.0
    

    Where:

    • hello.yaml is the path of the file to upload.
    • my-package is the package to upload.
    • 1.0.0 is the version of the artifact. You can't overwrite an existing version in the repository.

View artifacts in the repository

To verify that your artifact was added to the repository, you can list all artifacts by running the following command:

gcloud artifacts files list

The response includes the file details in the format PACKAGE:VERSION:FILE_NAME.

In the following example, hello.yaml is the FILE_NAME:

FILE: my-package:1.0.0:hello.yaml
CREATE_TIME: 2023-03-09T20:55:07
UPDATE_TIME: 2023-03-09T20:55:07
SIZE (MB): 0.000
OWNER: projects/my-project/locations/us-central1/repositories/quickstart-generic-repo/packages/my-package/versions/1.0.0

Download a generic artifact

To download a generic artifact from your repository, run the following command:

gcloud artifacts generic download \
    --name=hello.yaml \
    --package=my-package \
    --version=1.0.0 \
    --destination=DESTINATION

Where:

  • hello.yaml is the name of the file to download.
  • my-package is the package to download.
  • 1.0.0 is the version of the artifact.

Replace DESTINATION with the directory in your local file system where you want to save the download. The destination folder must already exist or the command will fail.

Clean up

To avoid incurring charges to your Google Cloud account for the resources used in this tutorial, either delete the project that contains the resources, or keep the project and delete the repository.

Delete the project

    Delete a Google Cloud project:

    gcloud projects delete PROJECT_ID

Delete the repository

Before you remove a repository, ensure that any packages that you want to keep are available in another location.

  1. To delete the quickstart-generic-repo repository, run the following command:

    gcloud artifacts repositories delete quickstart-generic-repo
    
  2. If you want to remove the default repository and location settings that you configured for the active gcloud configuration, run the following commands:

    gcloud config unset artifacts/repository
    gcloud config unset artifacts/location
    

What's next