[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-18。"],[[["\u003cp\u003eCloud Build allows you to manage and specify source-code dependencies separately from the build process by listing Git repositories in your build configuration file.\u003c/p\u003e\n"],["\u003cp\u003eIf no dependencies are listed, Cloud Build will clone the source code repository containing the build configuration, but if dependencies are specified, only those repositories will be cloned.\u003c/p\u003e\n"],["\u003cp\u003eDependencies in your configuration file must be either public repositories or connected to Cloud Build via Developer Connect, and they are cloned in the order specified before any build logic executes.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003edependencies\u003c/code\u003e stanza in the build configuration file is where you list the repositories, specifying details like the URL or Developer Connect resource path, revision, submodule settings, depth, and destination path.\u003c/p\u003e\n"],["\u003cp\u003eIf using a Developer Connect repository, ensure that the Cloud Build service account has the \u003ccode\u003eDeveloper Connect Read Token Accessor\u003c/code\u003e role and that the build is in the same region as the Developer Connect connection.\u003c/p\u003e\n"]]],[],null,["# Manage build dependencies\n\nThis page explains how you can specify build dependencies. Cloud Build\nlets you manage source-code dependencies separately from the build process.\n\nIn your build configuration file, you can list one or more Git repositories to\nclone for your build, and the order in which to fetch them. Specifying\ndependencies in this way separates dependency fetching from the build\nprocess itself.\n\nIf you don't include any dependencies in your build configuration file,\nCloud Build clones the source code repository that contains your build\nconfiguration file (for triggered builds) or the repository that contains your\nsource code (for builds that you invoke from the command line). If you do\ninclude dependencies in your build configuration file, Cloud Build\ndoesn't clone any repositories that aren't specified in the `dependencies`\nfield.\n\nAny source code repository you specify in the `dependencies` field must be\nconnected to Cloud Build using Developer Connect, or else\nbe a public repository.\n\nDependencies are cloned in the order that you specify them in this\nconfiguration. Also, dependency fetching occurs before any user-specified logic\nis executed. Thus, dependency fetching is trusted.\n\nDependencies are shown in the **Build dependencies** tab of the\n**Build details** page.\n\nBefore you begin\n----------------\n\nThe instructions on this page assume that you have one or more Git repositories\nthat are either public repositories or are\n[linked](/developer-connect/docs/connect-github-repo) using\nDeveloper Connect.\n\n\nTo get the permissions that\nyou need to add a Developer Connect repository as a dependency,\n\nask your administrator to grant you the\n\n\nDeveloper Connect Read Token Accessor (`developerconnect.readTokenAccessor`)\nIAM role on your service account.\n\n\nFor more information about granting roles, see [Manage access to projects, folders, and organizations](/iam/docs/granting-changing-revoking-access).\n\n\nYou might also be able to get\nthe required permissions through [custom\nroles](/iam/docs/creating-custom-roles) or other [predefined\nroles](/iam/docs/roles-overview#predefined).\n\nSpecify dependencies\n--------------------\n\nYou specify dependencies by adding a `dependencies` stanza to your build\nconfiguration file. `dependencies` is a top-level property in the build config,\nbut you can put it anywhere in the file.\n\nThe following is the syntax for the `dependencies` stanza: \n\n### YAML\n\n dependencies:\n - gitSource:\n repository:\n url: '\u003cvar translate=\"no\"\u003eURL\u003c/var\u003e'\n developerConnect: '\u003cvar translate=\"no\"\u003eRESOURCE_PATH\u003c/var\u003e'\n revision: '\u003cvar translate=\"no\"\u003eREVISION\u003c/var\u003e'\n recurseSubmodules: '\u003cvar translate=\"no\"\u003etrue|false\u003c/var\u003e'\n depth: \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003eDEPTH\u003c/span\u003e\u003c/var\u003e'\n destPath: '\u003cvar translate=\"no\"\u003eDEST_PATH\u003c/var\u003e'\n\n### JSON\n\n {\n \"dependencies\": {\n \"gitSource\": {\n \"repository\": {\n \"url\": \"\u003cvar translate=\"no\"\u003eURL\u003c/var\u003e\"\n \"developerConnect\": \"\u003cvar translate=\"no\"\u003eRESOURCE_PATH\u003c/var\u003e\"\n },\n \"revision\": \"\u003cvar translate=\"no\"\u003eREVISION\u003c/var\u003e\",\n \"recurseSubmodules\": \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-kc\"\u003etrue\u003c/span\u003e\u003cspan class=\"devsite-syntax-err\"\u003e|\u003c/span\u003e\u003cspan class=\"devsite-syntax-kc\"\u003efalse\u003c/span\u003e\u003c/var\u003e,\n \"depth\": \"\u003cvar translate=\"no\"\u003eDEPTH\u003c/var\u003e\",\n \"destPath\": \"\u003cvar translate=\"no\"\u003eDEST_PATH\u003c/var\u003e\",\n },\n },\n }\n\nYou must specify either a URL or a resource path. Specify a resource path if\nthe repository to fetch is connected to Cloud Build using\nDeveloper Connect.\n\nReplace the following values:\n\n- \u003cvar translate=\"no\"\u003eURL\u003c/var\u003e: Optional. The HTTPS URL of the repository to fetch.\n- \u003cvar translate=\"no\"\u003eRESOURCE_PATH\u003c/var\u003e: Optional. The Google Cloud resource\n path to a Developer Connect repository. For example,\n `projects/my-project/locations/us-central1/connections/my-connection/gitRepositoryLinks/my-repo`.\n\n- \u003cvar translate=\"no\"\u003eREVISION\u003c/var\u003e: Required. The version, commit hash, tag, or\n branch name to fetch from the repository.\n\n- `recurseSubmodules`: '\u003cvar translate=\"no\"\u003etrue|false\u003c/var\u003e': Whether to fetch\n submodules.\n\n- \u003cvar translate=\"no\"\u003eDEPTH\u003c/var\u003e: Optional, how deep into the repository history\n to fetch. If not specified, the latest commit is fetched.\n\n - `1`: the latest commit\n - `2`: the last two commits\n - `3`: the last three commits\n - `-1`: all commits\n- \u003cvar translate=\"no\"\u003eDEST_PATH\u003c/var\u003e: Required. The path to the directory into\n which the repository is cloned. For example, `my/repo`.\n\n When you set the `dest_path` the repository is fetched in\n `/workspace/\u003cdest_path\u003e`. The `dest_path` value must be a path relative to the\n working directory of the build.\n\nSpecify a Developer Connect repository as a dependency\n------------------------------------------------------\n\n- If you specify a Developer Connect repository as a dependency, then\n you must grant the `Developer Connect Read Token Accessor` role to the\n Cloud Build service account. For more information, see\n [Grant Cloud Build access to a Developer Connect repository](/developer-connect/docs/repositories/connect-repository#grant-access).\n\n- Your build must be in the same region as the Developer Connect\n connection.\n\nWhat's next\n-----------\n\n- Learn how to [connect a repository to Cloud Build using\n Cloud Build repositories](/build/docs/repositories).\n\n- Learn how to [connect a repository to Cloud Build using\n Developer Connect](/developer-connect/docs/overview)."]]