1

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

Rodolfo Picoreti
  • 443
  • 3
  • 15

3 Answers3

3

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

Rodolfo Picoreti
  • 443
  • 3
  • 15
  • I tried that but my .git/config doesn't get updated after it: Initialized empty Git repository in /workspace/.git/ [core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true – Edmondo Sep 06 '20 at 18:49
1

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
Andrei Popa
  • 159
  • 9
  • You probably shouldn't be cryptic with what you are doing here. For future reference, this should be added in CloudBuild->Triggers->Edit->Configuration->Location->Open Editor – nathanfranke Jun 08 '21 at 00:16
0

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.

AlexDotAll
  • 41
  • 3