【问题标题】:Use git commands with Google Cloud Builder在 Google Cloud Builder 中使用 git 命令
【发布时间】:2023-03-12 14:11:01
【问题描述】:

我正在尝试使用 Google Cloud Build 和 GitHub 来制作 CI/CD 管道。 但是我在 GCB 上苦苦挣扎……

下面,一个非常简单的管道:

  1. 运行npm install --> 有效
  2. 运行npm test-->它可以工作
  3. 运行npm run css:ALL(rm一些文件+做一些缩小的东西)-->似乎工作
  4. 运行一些git 命令--> 不起作用

错误:

Step #3: fatal: not a git repository (or any parent up to mount point /)
Step #3: Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).

cloudbuild.yaml

steps:
  - name: 'gcr.io/cloud-builders/npm'
    args: ['install']
  # run test
  - name: 'gcr.io/cloud-builders/npm'
    args: ['test']
  # build css files
  - name: 'gcr.io/cloud-builders/npm'
    args: ['run', 'css:ALL']
  # git stuff
  - name: 'gcr.io/cloud-builders/git'
    args: ['add', '-A']
  - name: 'gcr.io/cloud-builders/git'
    args: ['commit', '-m', '"some message"']

你有什么线索吗?

我的目标只是将git add 全部构建并push 将它们返回到我的branch。 谢谢

【问题讨论】:

  • 你的本地仓库有 .git 文件夹吗?也许你可以试试git init

标签: git github google-cloud-build


【解决方案1】:

Cloud Build 是一款很棒的产品!!有一些无聊的东西... .git 文件夹没有与源代码一起复制。

如果您手动运行云构建,只需在存储库的根目录中添加一个空的 .gcloudignore 文件。多亏了它,.git 目录不会被忽略并与您的代码一起上传。

但是这个技巧不适用于触发器。为此,我使用这一步

steps:
- name: 'gcr.io/cloud-builders/git'
  entrypoint: /bin/bash
  args:
    - -c
    - |
        # Cloud Build doesn't recover the .git file. Thus checkout the repo for this
        git clone --branch $BRANCH_NAME https://github.com/path/to/yourRepo.git /tmp/repo ;
        # Copy only the .git file
        mv /tmp/repo/.git .

然后您可以使用 git,并使用有效且现有的 .git 目录

【讨论】:

  • 或者你可以添加git init
  • 对于触发方法,是否适用于私有repos?
  • @YeLinAung 在这种情况下使用谷歌源代码库镜像
猜你喜欢
  • 1970-01-01
  • 2019-09-15
  • 2020-07-27
  • 2020-07-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-30
  • 1970-01-01
相关资源
最近更新 更多