我正在开发一个项目,在该项目中我们为所有代码更新维护一个 Gitlab 存储库。
我创建了一个 Cloud Build 触发器,通过引用源使用 Webhook URL 连接到 Gitlab 存储库 -https://cloud.google.com/build/docs/automating-builds/build-repos-from-gitlab#console https://cloud.google.com/build/docs/automating-builds/build-repos-from-gitlab#console.
生成 SSH 密钥并将公钥添加到 Gitlab 帐户。
将 SSH 密钥存储在 Secret Manager 中,然后使用 Webhook URL 创建云构建触发器。
steps:
# first, setup SSH:
# 1- save the SSH key from Secret Manager to a file
# 2- add the host key to the known_hosts file
- name: gcr.io/cloud-builders/git
args:
- '-c'
- |
echo "$$SSHKEY" > /root/.ssh/id_rsa
chmod 400 /root/.ssh/id_rsa
ssh-keyscan gitlab.com > /root/.ssh/known_hosts
entrypoint: bash
secretEnv:
- SSHKEY
volumes:
- name: ssh
path: /root/.ssh
# second, clone the repository
- name: gcr.io/cloud-builders/git
args:
- clone
- '-n'
- '[email protected] /cdn-cgi/l/email-protection/GITLAB_REPO'
- .
volumes:
- name: ssh
path: /root/.ssh
# third, checkout the specific commit that invoked this build
- name: gcr.io/cloud-builders/git
args:
- checkout
- $_TO_SHA
availableSecrets:
secretManager:
- versionName: PATH_TO_SECRET_VERSION
env: SSHKEY
这是 Cloud Build Trigger 的 YAML 配置文件的示例代码,我添加了另一个步骤,使用 Gitlab Repo 上提供的 Dockerfile 在 Container Registry 中创建 Docker 映像。
但触发器无法构建。
我注意到我的 Google Cloud Console 中的另一点是,下面没有 id_rsa 文件.ssh
目录。生成 ssh 密钥后也没有 id_rsa 文件。但上面的示例代码是我从上面共享的源代码中获取的,它定义了 id_rsa 文件,用于将其保存到文件中。
我尝试将该路径更改为存储在.ssh
目录。但这也没有帮助。
我在使用此源文档连接到 Gitlab Repo 时遇到了困境。
我提供了所需的 Gitlab 存储库路径和 Secret Managers Secret 的路径,其中存储了连接到 Gitlab Repo 的 ssh 密钥。
任何建议都会有帮助。
谢谢
None
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)