【问题标题】:Cloudbuild to trigger Github merge to master branchCloudbuild 触发 Github 合并到 master 分支
【发布时间】:2021-12-29 05:38:40
【问题描述】:

我有一个 Google Cloudbuild 管道,用于测试提交到我的 Github 存储库的开发分支的代码,并将代码部署到开发环境。我想在管道中添加另一个步骤,在成功部署到开发环境后将我的 dev 分支与 prod 分支合并。有什么方法可以实现吗?

【问题讨论】:

    标签: git github google-cloud-platform google-cloud-build


    【解决方案1】:

    您可能可以在 Cloud Build 触发器“执行”的“cloudbuild.yaml”(或其他名称)文件中执行此操作。

    根据我的经验,您将需要一对密钥 - 公钥应该在 GitHub 中,私钥值 - 作为秘密存储在 Secret Manager 中。

    因此,在yaml文件中你可能需要使用(根据你的情况改变,不要这样使用):

      volumes:
      - name: 'ssh'
        path: /root/.ssh
    

    到目前为止:

    1. 获取私钥(来自秘密)并将其保存为文件/root/.ssh/github,使用类似gcloud secrets versions access latest ...
    2. 更改权限chmod 600 /root/.ssh/github
    3. 创建配置文件:
    cat <<EOF >/root/.ssh/config
    Hostname github.com
    IdentityFile /root/.ssh/github
    EOF
    
    1. 将 GitHub 公钥保存到 known_hosts 文件ssh-keyscan -t rsa github.com &gt; /root/.ssh/known_hosts

    之后,您(实际上是您的 Cloud Build 服务帐户,使用提供的凭据)可以使用普通的 git 命令对 GitHub 存储库进行任何需要的操作(取决于 GitHub 中授予的权限)。

    【讨论】:

      猜你喜欢
      • 2019-01-08
      • 2016-02-03
      • 1970-01-01
      • 2013-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-30
      相关资源
      最近更新 更多