【问题标题】:GCP Artifact Registry - create repo only when it does not existGCP Artifact Registry - 仅在不存在时创建 repo
【发布时间】:2021-09-30 06:37:03
【问题描述】:

我正在尝试将 repo 创建放入 Github Action for CI/CD。

但是,我发现无法重复下面的创建命令。

gcloud artifacts repositories create my-repo

如果我在已经有 repo 的情况下执行此操作,则操作将失败。

只有在没有这样的 repo 时才执行 create 的好方法吗?

【问题讨论】:

    标签: google-cloud-platform github-actions google-artifact-registry


    【解决方案1】:

    如果你没有太多的存储库,我会:

    • 用 (listing repositories) 的结果设置一个变量

        gcloud artifacts repositories list|grep my-repo
      

    或者:更可扩展,用gcloud artifacts repositories describe的结果设置变量

    gcloud artifacts repositories describe my-repo --location=us-west1
    
    • 仅当变量为“1”(grep 失败或 describe 失败)时才执行 gcloud create 命令

    查看具体的(GitHub 工作流程)example here

    【讨论】:

    • 当我有很多存储库时,我认为这不是一个可扩展的解决方案..
    • @HumbleCoder 这就是为什么我的回答以“如果您没有太多存储库”开头的原因
    • @HumbleCoder 我已经用一个可扩展的可能解决方案编辑了答案,即使你有很多存储库也可以工作。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-08-12
    • 1970-01-01
    • 1970-01-01
    • 2021-03-19
    • 2017-11-16
    • 2021-08-28
    • 1970-01-01
    相关资源
    最近更新 更多