HumbleCoder
HumbleCoder

Reputation: 596

GCP Artifact Registry - create repo only when it does not exist

I am trying to put repo creation in Github Action for CI/CD.

However, I have found that I cannot repeat the following creation command.

gcloud artifacts repositories create my-repo

If I do this when there already is a repo, the operation will simply fail.

Is there a good way to execute create only if there isn't such repo?

Upvotes: 2

Views: 1771

Answers (1)

VonC
VonC

Reputation: 1328292

If you don't have too many repositories, I would:

  • set a variable with the result of (listing repositories)

      gcloud artifacts repositories list|grep my-repo
    

Or: more scalable, set the variable with the result of gcloud artifacts repositories describe

gcloud artifacts repositories describe my-repo --location=us-west1
  • execute the gcloud create command only if that variable is '1' (the grep failed, or the describe failed)

See a concrete (GitHub workflow) example here.

Upvotes: 1

Related Questions