将GCP云构建触发器与GitLab存储库连接

发布于 2025-02-02 19:32:30 字数 1994 浏览 3 评论 0 原文

我正在研究一个项目,在该项目中,我们维护一个代码中所有更新的GitLab存储库。
我已经创建了一个云构建触发器,通过引用source- https://cloud.google.com/build/docs/automating-builds/build-repos-repos-from-gitlab#console



生成一个SSH键&将公共密钥添加到Gitlab帐户中。
存储在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]/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

这是用于云构建触发器的YAML配置文件的示例代码,我添加了另一个步骤来使用Gitlab Repo上可用的Dockerfile在容器注册表中创建Docker Image。 但是扳机无法构建。
我注意到我的Google云控制台中的另一点, .ssh 目录下没有ID_RSA文件。生成SSH键后,也没有ID_RSA文件。但是我从上面共享的源中获得的上述示例代码定义了用于将其保存到文件的ID_RSA文件。
我试图将该路径更改为存储在 .ssh 目录中的SSH密钥专用文件。但这也无济于事。 我在使用此源文档连接到GitLab存储库的困境中处于困境。 我提供了所需的gitlab存储库路径&通往秘密经理秘密的路径,该秘密存储SSH密钥连接到Gitlab repo。


任何建议都会有所帮助。
谢谢

I am working on a project in which we maintain a Gitlab Repository for all updates in code.
And I have created a Cloud Build Trigger to connect to Gitlab Repository using Webhook URL by referencing the source- https://cloud.google.com/build/docs/automating-builds/build-repos-from-gitlab#console.

Generated an SSH Key & added the public key to Gitlab Account.
Stored SSH Key in Secret Manager & then created a Cloud Build Trigger using 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]/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

This is the sample code for the YAML Config file for Cloud Build Trigger, I have added another step to create a Docker Image in Container Registry using the Dockerfile available on Gitlab Repo.
But the Trigger is unable to build.
I have noticed another point in my Google Cloud Console that there is no id_rsa file under the .ssh directory. After generating the ssh key also there is no id_rsa file. But the above sample code which I got from a source shared above defines the id_rsa file for saving it to a file.
I tried to change that path to my ssh key private file stored in the .ssh directory. But that too didn't help.
I am in a dilemma on connecting to Gitlab Repo using this source documentation.
I have provided the required Gitlab Repository Path & the Path to Secret Managers Secret which stores the ssh key to connect to Gitlab Repo.

Any Suggestions will be helpful.
Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文