I have a Google Cloud Build trigger which I've set to a Github repo which has the option selected Cloud Build configuration file (yaml or json)
.
The repo has a submodule but I'm afraid the submodule is not populated by default. When I create a Compute VM from the resulting Docker image from the Cloud Build process, the logs show:
DEFAULT 2023-05-22T01 [resource.labels.instanceId: XXX-build] ImportError: cannot import name 'mysubmodule' from 'mysubmodule' (unknown location)
I believe the issue is the submodules do not pull like when using git clone
on a desktop. So I add the git submodule update --init
command in the cloudbuild.yaml
file below but the issue is the Cloud Build process doesn't understand the submodule command.
I've tried:
Changing the path to SSH gitpath: Cloud build failing on git submodules
Adding git command in cloudbuild.yaml:
- name: "gcr.io/cloud-builders/git"
args:
- submodule update --init --recursive
Result
Step #0: git: 'submodule update --init --recursive' is not a git command. See 'git --help'.
There is also this bug: https://issuetracker.google.com/issues/123060361
2025 Update: The manage-dependencies feature in Cloud Build now supports submodules. My source lives in Github, so I'm providing some documentation for what I did. YMMV.
cloudbuild.yaml
. Add the top-level dependencies
key to clone the submodule and then the project. E.g.:dependencies:
- gitSource:
repository:
developerConnect: 'projects/my-project-0001/locations/us-central1/connections/github-kenberland/gitRepositoryLinks/kenberland-submodule'
revision: master
recurseSubmodules: false
depth: 1
destPath: submod
- gitSource:
repository:
developerConnect: 'projects/my-project-0001/locations/us-central1/connections/github-kenberland/gitRepositoryLinks/kenberland-my-project'
revision: master
recurseSubmodules: true
depth: 1
destPath: .