【问题标题】:Clone private GitHub repo in Google Cloud Build yaml在 Google Cloud Build yaml 中克隆私有 GitHub 存储库
【发布时间】:2020-10-08 20:30:13
【问题描述】:

根据 Cloud Build 文档中标题为访问私有 GitHub 存储库note

当您使用 Cloud Build 触发器运行构建时,您可以自动连接到您拥有的任何私有存储库,而无需将凭据存储在 Secret Manager 中。

基于此,我尝试 git clone 我的私人 GitHub 存储库(没有将 ssh 密钥从 Secret Manager 传输到 ssh 文件,文档指出使用构建触发器是不必要的)无济于事。在我的cloudbuild.yaml 文件中使用下面的 ssh:

steps:
- name: google/cloud-sdk:alpine
  id: Clone repo
  entrypoint: git
  args: ['clone', 'git@github.com:my-org/my-repo.git']

导致错误:

Step #0: Host key verification failed.
Step #0: fatal: Could not read from remote repository.

并使用 https

  args: ['clone', 'https://github.com/my-org/my-repo.git']

我明白了:

Step #0 - "Clone repo": fatal: could not read Username for 'https://github.com': No such device or address

有什么方法可以在cloudbuild.yaml 中克隆私有 GitHub 存储库,而无需在克隆之前将 ssh 密钥从 Secret Manager 繁琐地传输到卷?任何提示将不胜感激。

【问题讨论】:

  • 我不明白。您添加的注释适用于 Cloud Build 中的触发器,您希望您的构建由 Cloud 构建触发器触发(在这种情况下,您不需要执行此操作)还是手动触发?
  • 是的,无论您使用触发器还是在 CLI 上构建,都需要 cloudbuild.yaml。我的 cloudbuild.yaml 文件位于私有 GitHub 存储库中。每当推送特定标签时都会触发构建。在我的构建(在 cloudbuild.yaml 中配置)中,我必须克隆 git 存储库,对其进行编辑,然后再次推送。

标签: github ssh google-cloud-platform yaml google-cloud-build


【解决方案1】:

正如note分享中提到的,如果你想避开Secret Manager,你需要配置你的Cloud Build Trigger

构建触发器设置步骤涉及使用您的用户名和密码对源存储库进行身份验证。

因此,当您触发此 Cloud Build 触发器时,它不会在 Secret Manager 中询问您的凭据,因为身份验证已在前面的步骤(触发器设置)中提供。

【讨论】:

    【解决方案2】:

    我在github 中发现了一个类似的问题,它可以帮助您解决使用 ssh 时的错误。

    对于 https 方法,我建议您从 url 中删除 https://github.com。 我发现另一个问题是在 github 中创建的,它可以帮助您在使用 https 方法时解决问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-19
      • 2019-07-18
      • 2020-09-23
      • 1970-01-01
      • 1970-01-01
      • 2021-12-31
      • 2022-08-08
      • 2019-12-27
      相关资源
      最近更新 更多