Manage build dependencies

This page explains how you can specify build dependencies. Cloud Buildlets you manage source-code dependencies separately from the build process.

In your build configuration file, you can list one or more Git repositories toclone for your build, and the order in which to fetch them. Specifyingdependencies in this way separates dependency fetching from the buildprocess itself.

If you don't include any dependencies in your build configuration file,Cloud Build clones the source code repository that contains your buildconfiguration file (for triggered builds) or the repository that contains yoursource code (for builds that you invoke from the command line). If you doinclude dependencies in your build configuration file, Cloud Builddoesn't clone any repositories that aren't specified in thedependenciesfield.

Any source code repository you specify in thedependencies field must beconnected to Cloud Build using Developer Connect, or elsebe a public repository.

Dependencies are cloned in the order that you specify them in thisconfiguration. Also, dependency fetching occurs before any user-specified logicis executed. Thus, dependency fetching is trusted.

Dependencies are shown in theBuild dependencies tab of theBuild details page.

Before you begin

The instructions on this page assume that you have one or more Git repositoriesthat are either public repositories or arelinked usingDeveloper Connect.

To ensure that has the necessary permissions to add a Developer Connect repository as a dependency, ask your administrator to grant the Developer Connect Read Token Accessor (developerconnect.readTokenAccessor) IAM role on your service account. For more information about granting roles, seeManage access to projects, folders, and organizations.

Your administrator might also be able to give the required permissions throughcustom roles or otherpredefined roles.

Specify dependencies

You specify dependencies by adding adependencies stanza to your buildconfiguration file.dependencies is a top-level property in the build config,but you can put it anywhere in the file.

The following is the syntax for thedependencies stanza:

YAML

dependencies:-gitSource:repository:url:'URL'developerConnect:'RESOURCE_PATH'revision:'REVISION'recurseSubmodules:'true|false'depth:DEPTH'destPath:'DEST_PATH'

JSON

{"dependencies":{"gitSource":{"repository":{"url":"URL""developerConnect":"RESOURCE_PATH"},"revision":"REVISION","recurseSubmodules":true|false,"depth":"DEPTH","destPath":"DEST_PATH",},},}

You must specify either a URL or a resource path. Specify a resource path ifthe repository to fetch is connected to Cloud Build usingDeveloper Connect.

Replace the following values:

  • URL: Optional. The HTTPS URL of the repository tofetch.
  • RESOURCE_PATH: Optional. The Google Cloud resourcepath to a Developer Connect repository. For example,projects/my-project/locations/us-central1/connections/my-connection/gitRepositoryLinks/my-repo.

  • REVISION: Required. The version, commit hash, tag, orbranch name to fetch from the repository.

  • recurseSubmodules: 'true|false': Whether to fetchsubmodules.

  • DEPTH: Optional, how deep into the repository historyto fetch. If not specified, the latest commit is fetched.

    • 1: the latest commit
    • 2: the last two commits
    • 3: the last three commits
    • -1: all commits
  • DEST_PATH: Required. The path to the directory intowhich the repository is cloned. For example,my/repo.

    When you set thedest_path the repository is fetched in/workspace/<dest_path>. Thedest_path value must be a path relative to theworking directory of the build.

Specify a Developer Connect repository as a dependency

To specify a Developer Connect repository as a dependency, thefollowing must be true:

What's next

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-02-19 UTC.