git - 将 git 命令与 Google Cloud Builder 结合使用

我正在尝试将 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).

云构建.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 回到我的分支。 谢谢

最佳答案

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 目录

https://stackoverflow.com/questions/60575602/

相关文章:

r - 按列汇总 : mean and sum

javascript - 在 Promise 完成后让 React 重新渲染

Django - 检查两个密码哈希是否具有相同的原始密码

r - 如何在 R 中绘制用 kmeans 获得的簇的 3D 图?

javascript - Vue-Apexcharts 饼图总数不显示

amazon-web-services - AWS CLI : Could not connect

reactjs - 功能组件在 setState 更新 Hook 后不重新渲染

flutter - 如何在 flutter, android studio 中不生成红色框,

python - 在 hvplot 中自定义标记列表

pandas - 在 Pandas 中使用带有多索引的聚合