gitgit-submodulesgoogle-cloud-build

Cloud Build does not populate Git submodules


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:

There is also this bug: https://issuetracker.google.com/issues/123060361


Solution

  • 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.

    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: .