Google Cloud Build - Cant Update Submodules

若如初见. 提交于 2021-02-11 15:27:28

问题


I configured google cloud build (GCB) to trigger a build on one of my repositories in Github. This repository requires another git repository in order to be built. This other repository is configured using a git submodule.

I search and at the moment it looks like GCB do not support submodules. So I am trying to run git submodule update --init manually on the source code that GCB downloaded, but there is not .gitdirectory on it and the command fails.

What am I missing here?

I am using this issue as reference: https://github.com/GoogleCloudPlatform/cloud-builders/issues/435


回答1:


If trigger your build using github it will not work because of the lack of the .git folder. In order for it to work, all repositories need to be mirrored by Cloud Source Repositories. Then, the submodule can be updated like this:

- 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

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




回答2:


Sometimes you get an error with GIT_DISCOVERY_ACROSS_FILESYSTEM or the missing .git folder. The following worked for me:

- 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



回答3:


For someone like me, who is using submodules in Bitbucket and ran into similar problems with Cloud Build: As soon as you mirror your repositories into the Cloud Source Repository, the submodule URLs are not allowed to have the .git extension.

For example for the main repository https://source.cloud.google.com/Project_ID/main_repo and submodules a, b in the "submodules" folder the .gitmodules configuration might look similar to this

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

Previously, I used for URLs ../a.git and ../b.git which works fine in Bitbucket but not in Cloud Source Repository.



来源:https://stackoverflow.com/questions/59180893/google-cloud-build-cant-update-submodules

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!