0

我配置了 google cloud build (GCB) 以触发我在 Github 中的一个存储库上的构建。此存储库需要另一个 git 存储库才能构建。这个其他存储库是使用 git 子模块配置的。

我搜索了一下,目前看起来 GCB 不支持子模块。所以我试图git submodule update --init在 GCB 下载的源代码上手动运行,但是上面没有.git目录并且命令失败。

我在这里想念什么?

我使用这个问题作为参考:https ://github.com/GoogleCloudPlatform/cloud-builders/issues/435

4

3 回答 3

3

如果使用 github 触发您的构建,由于缺少 .git 文件夹,它将无法工作。为了使其正常工作,所有存储库都需要由 Cloud Source Repositories 镜像。然后,子模块可以像这样更新:

- name: 'gcr.io/cloud-builders/git'
  entrypoint: 'bash'
  args:
  - '-c'
  - |
    git config -f .gitmodules submodule.[my-sub-repo-name].url https://source.developers.google.com/p/[my-project]/r/github_[my-sub-repo-name]
    git submodule init
    git submodule update

参考:https ://github.com/GoogleCloudPlatform/cloud-builders/issues/26

于 2019-12-10T13:55:02.860 回答
1

有时您会收到错误GIT_DISCOVERY_ACROSS_FILESYSTEM或缺少.git文件夹。以下对我有用:

- id: git-submodule
  name: 'gcr.io/cloud-builders/git'
  entrypoint: 'bash'
  env: ['GIT_DISCOVERY_ACROSS_FILESYSTEM=1']
  args:
  - '-c'
  - |
    git init
    git config -f .gitmodules submodule.[my-sub-repo-name].url https://source.developers.google.com/p/[my-project]/r/github_[my-sub-repo-name]
    git submodule init
    git submodule update
于 2020-03-24T13:26:56.337 回答
0

对于像我这样在 Bitbucket 中使用子模块并在 Cloud Build 中遇到类似问题的人:一旦您将存储库镜像到 Cloud Source Repository,子模块 URL 就不允许具有.git扩展名。

例如,对于主存储库https://source.cloud.google.com/Project_ID/main_repoa, b“子模块”文件夹中的子模块,.gitmodules配置可能与此类似

[submodule "submodules/a"]
    path = submodules/a
    url = ../a
[submodule "submodules/b"]
    path = submodules/b
    url = ../b

以前,我用于 URL ../a.git../b.git它在 Bitbucket 中运行良好,但在 Cloud Source Repository 中运行良好。

于 2020-04-24T07:37:42.130 回答