Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Halaman ini menjelaskan cara menentukan dependensi build. Cloud Build
memungkinkan Anda mengelola dependensi kode sumber secara terpisah dari proses build.
Dalam file konfigurasi build, Anda dapat mencantumkan satu atau beberapa repositori Git yang akan di-clone untuk build, dan urutan pengambilan repositori tersebut. Menentukan
dependensi dengan cara ini memisahkan pengambilan dependensi dari proses
build itu sendiri.
Jika Anda tidak menyertakan dependensi apa pun dalam file konfigurasi build,
Cloud Build akan meng-clone repositori kode sumber yang berisi file konfigurasi
build (untuk build yang dipicu) atau repositori yang berisi kode sumber (untuk build yang Anda panggil dari command line). Jika Anda menyertakan dependensi dalam file konfigurasi build, Cloud Build tidak akan meng-clone repositori yang tidak ditentukan di kolom dependencies.
Setiap repositori kode sumber yang Anda tentukan di kolom dependencies harus
dihubungkan ke Cloud Build menggunakan Developer Connect, atau
berupa repositori publik.
Dependensi di-clone dalam urutan yang Anda tentukan dalam konfigurasi ini. Selain itu, pengambilan dependensi terjadi sebelum logika yang ditentukan pengguna
dieksekusi. Dengan demikian, pengambilan dependensi dapat dipercaya.
Dependensi ditampilkan di tab Build dependencies di halaman
Build details.
Sebelum memulai
Petunjuk di halaman ini mengasumsikan bahwa Anda memiliki satu atau beberapa repositori Git yang merupakan repositori publik atau ditautkan menggunakan Developer Connect.
Untuk mendapatkan izin yang
diperlukan untuk menambahkan repositori Developer Connect sebagai dependensi,
minta administrator untuk memberi Anda
Peran IAM Pengakses Token Baca Developer Connect (developerconnect.readTokenAccessor)
di akun layanan Anda.
Untuk mengetahui informasi selengkapnya tentang cara memberikan peran, lihat Mengelola akses ke project, folder, dan organisasi.
Anda menentukan dependensi dengan menambahkan stanza dependencies ke file konfigurasi build. dependencies adalah properti tingkat teratas dalam konfigurasi build,
tetapi Anda dapat menempatkannya di mana saja dalam file.
Berikut adalah sintaksis untuk stanza dependencies:
Anda harus menentukan URL atau jalur resource. Tentukan jalur resource jika repositori yang akan diambil terhubung ke Cloud Build menggunakan Developer Connect.
Ganti nilai berikut:
URL: Opsional. URL HTTPS repositori yang akan diambil.
RESOURCE_PATH: Opsional. Jalur Google Cloud resource
ke repositori Developer Connect. Contohnya,
projects/my-project/locations/us-central1/connections/my-connection/gitRepositoryLinks/my-repo.
REVISION: Wajib diisi. Versi, hash commit, tag, atau
nama cabang yang akan diambil dari repositori.
recurseSubmodules: 'true|false': Apakah akan mengambil
submodul.
DEPTH: Opsional, seberapa dalam histori repositori
yang akan diambil. Jika tidak ditentukan, commit terbaru akan diambil.
1: commit terbaru
2: dua commit terakhir
3: tiga commit terakhir
-1: semua commit
DEST_PATH: Wajib diisi. Jalur ke direktori tempat repositori di-clone. Contoh, my/repo.
Saat Anda menetapkan dest_path, repositori akan diambil di
/workspace/<dest_path>. Nilai dest_path harus berupa jalur relatif ke
direktori kerja build.
Menentukan repositori Developer Connect sebagai dependensi
Jika Anda menentukan repositori Developer Connect sebagai dependensi, Anda harus memberikan peran Developer Connect Read Token Accessor ke akun layanan Cloud Build. Untuk mengetahui informasi selengkapnya, lihat Memberikan akses Cloud Build ke repositori Developer Connect.
Build Anda harus berada di region yang sama dengan koneksi Developer Connect.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-09-01 UTC."],[[["\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)."]]