Cloudbuild 触发 Github 合并到 master 分支
Cloudbuild to trigger Github merge to master branch
我有一个 Google Cloudbuild 管道,它测试提交到我的 Github 存储库的开发分支的代码,并将代码部署到开发环境。我想在管道中添加另一个步骤,在成功部署到开发环境后将我的开发分支与生产分支合并。有什么办法可以实现吗?
您可能可以在 Cloud Build 触发器 'executed' 的 'cloudbuild.yaml'(或其他名称)文件中执行此操作。
根据我的经验,您需要一对密钥 - public 密钥应该在 GitHub 中,私钥值 - 作为秘密存储在 Secret Manager 中。
因此,在yaml文件中你可能需要使用(根据你的情况改变,不要这样使用):
volumes:
- name: 'ssh'
path: /root/.ssh
到目前为止:
- 获取私钥(来自秘密)并使用
gcloud secrets versions access latest ...
之类的东西将其保存为文件 /root/.ssh/github
- 更改权限
chmod 600 /root/.ssh/github
- 创建配置文件:
cat <<EOF >/root/.ssh/config
Hostname github.com
IdentityFile /root/.ssh/github
EOF
- 将 GitHub public 密钥保存到 known_hosts 文件
ssh-keyscan -t rsa github.com > /root/.ssh/known_hosts
在那之后,您(实际上是您的 Cloud Build 服务帐户使用提供的凭据)可以使用 GitHub 存储库使用普通 git
命令。
我有一个 Google Cloudbuild 管道,它测试提交到我的 Github 存储库的开发分支的代码,并将代码部署到开发环境。我想在管道中添加另一个步骤,在成功部署到开发环境后将我的开发分支与生产分支合并。有什么办法可以实现吗?
您可能可以在 Cloud Build 触发器 'executed' 的 'cloudbuild.yaml'(或其他名称)文件中执行此操作。
根据我的经验,您需要一对密钥 - public 密钥应该在 GitHub 中,私钥值 - 作为秘密存储在 Secret Manager 中。
因此,在yaml文件中你可能需要使用(根据你的情况改变,不要这样使用):
volumes:
- name: 'ssh'
path: /root/.ssh
到目前为止:
- 获取私钥(来自秘密)并使用
gcloud secrets versions access latest ...
之类的东西将其保存为文件 - 更改权限
chmod 600 /root/.ssh/github
- 创建配置文件:
/root/.ssh/github
cat <<EOF >/root/.ssh/config
Hostname github.com
IdentityFile /root/.ssh/github
EOF
- 将 GitHub public 密钥保存到 known_hosts 文件
ssh-keyscan -t rsa github.com > /root/.ssh/known_hosts
在那之后,您(实际上是您的 Cloud Build 服务帐户使用提供的凭据)可以使用 GitHub 存储库使用普通 git
命令。