Untuk menggunakan contoh command line dalam panduan ini, instal dan konfigurasikan Google Cloud CLI.
Anda dapat menggunakan project Google Cloud yang sama untuk membuat
kumpulan pribadi dan build Cloud Build atau menggunakan project
yang berbeda. Jika build Anda berada dalam project yang berbeda dengan kumpulan private, tetapkan project default di gcloud CLI ke project tempat build Anda berasal:
gcloud config set project BUILD_ORIGIN_PROJECT_ID
Izin IAM
Untuk menjalankan build melalui gcloud CLI atau Cloud Build API, berikan peran WorkerPool User di project kumpulan pribadi kepada pengguna atau akun layanan yang meminta build.
Untuk menjalankan build otomatis menggunakan pemicu:
Jika project tempat Anda memulai build sama dengan project
tempat kumpulan pribadi Anda berada, Anda tidak perlu memberikan izin apa pun.
Jika project tempat Anda memulai build berbeda dengan project tempat pool pribadi Anda berada, berikan peran WorkerPool User ke akun layanan yang Anda gunakan dengan pemicu di project workerpool tempat build Anda dibuat:
Ganti nilai placeholder dalam perintah di atas dengan yang berikut ini:
PRIVATEPOOL_PROJECT_ID adalah ID project dengan kumpulan pribadi yang menjalankan build.
SERVICE_ACCOUNT adalah email akun layanan
yang Anda gunakan dengan pemicu yang menjalankan build.
Menjalankan build
Anda dapat mengirimkan build dari project Google Cloud yang sama tempat Anda membuat kumpulan pribadi atau dari project Google Cloud yang berbeda. Anda dapat menentukan kumpulan pribadi di file konfigurasi build atau langsung di perintah gcloud:
Menentukan kumpulan pribadi dalam file konfigurasi build:
Di file konfigurasi Cloud Build,
tambahkan opsi pool dan tentukan nama resource lengkap dari kumpulan pekerja
pribadi untuk menjalankan build:
{"steps":[{"name":"bash","args":["echo","I am running in a private pool!"]}],"options":{"pool":{"name":"projects/PRIVATEPOOL_PROJECT_ID/locations/REGION/workerPools/PRIVATEPOOL_ID"}}}
Ganti nilai placeholder dalam file konfigurasi di atas dengan nilai berikut:
PRIVATEPOOL_PROJECT_ID: Google Cloud project tempat kumpulan pribadi Anda berada.
REGION: region tempat Anda membuat kumpulan
pribadi.
PRIVATEPOOL_ID: ID pool pribadi unik yang Anda tentukan saat membuat private pool.
Gunakan file konfigurasi build yang dibuat di atas untuk menjalankan build melalui gcloud atau API
atau menggunakan pemicu. Jika instance Anda dihosting secara lokal, Cloud Build juga menyediakan dukungan fungsi pemicu untuk beberapa sistem pengelolaan kode sumber eksternal seperti GitHub Enterprise atau Bitbucket Server.
Menentukan kumpulan pribadi dalam perintah gcloud:
Anda dapat menentukan kumpulan pribadi dalam perintah gcloud, bukan dalam
file konfigurasi build. Misalnya, anggaplah Anda memiliki file konfigurasi build
berikut:
[[["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-08-18 UTC."],[[["\u003cp\u003eThis document details how to execute builds within private pools in Google Cloud, requiring prior setup of a private pool.\u003c/p\u003e\n"],["\u003cp\u003eTo run builds through the gcloud CLI or Cloud Build API, the user or service account initiating the build must have the \u003cstrong\u003eWorkerPool User\u003c/strong\u003e role in the private pool project.\u003c/p\u003e\n"],["\u003cp\u003eBuilds can originate from the same or a different Google Cloud project as the private pool, with necessary IAM permissions required if the build is being run in a separate project.\u003c/p\u003e\n"],["\u003cp\u003ePrivate pools can be specified in either the build configuration file using the \u003ccode\u003epool\u003c/code\u003e option, or directly within the \u003ccode\u003egcloud\u003c/code\u003e command using the \u003ccode\u003e--worker-pool\u003c/code\u003e flag.\u003c/p\u003e\n"],["\u003cp\u003eIf automated builds are being used with triggers and the projects differ, the service account of the trigger needs the \u003cstrong\u003eWorkerPool User\u003c/strong\u003e role on the project with the private pool.\u003c/p\u003e\n"]]],[],null,["# Run builds in a private pool\n\nThis document explains how to run builds in private pools. If you're new\nto private pools, read the [Private pools overview](/build/docs/private-pools/private-pools-overview).\n\nBefore you begin\n----------------\n\n- Make sure you've created a private pool using the steps in\n [Creating and managing private pools](/build/docs/private-pools/create-manage-private-pools).\n\n- To use the command-line examples in this guide, install and\n configure the [Google Cloud CLI](https://cloud.google.com/sdk).\n\n | **Note:** If you've installed gcloud CLI previously, make sure you have the latest available version by running `gcloud components update`.\n- You can either use the same Google Cloud project to create your\n private pool and your Cloud Build builds or use different\n projects. If your builds are in a different project from your private\n pool, set the default project in the gcloud CLI to the project where your\n builds originate:\n\n gcloud config set project \u003cvar translate=\"no\"\u003eBUILD_ORIGIN_PROJECT_ID\u003c/var\u003e\n\n### IAM permissions\n\n- To run builds via the gcloud CLI or the Cloud Build API, grant\n the **WorkerPool User** role in the private pool project to the user or service\n account that requests the build.\n\n- To run automated builds using triggers:\n\n - If the project in which you're starting the build is the same as the project in which your private pool exists, you don't need to grant any permissions.\n - If the project in which you're starting the build is different from the\n project in which your private pool exists, grant the **WorkerPool User**\n role to the service account you are using with your trigger on the\n workerpool project where your builds are created:\n\n ### Console\n\n 1. Open the **IAM** page in the Google Cloud console.\n\n [Open the IAM Permissions page](https://console.cloud.google.com/iam-admin/iam)\n 2. In the project selector drop-down menu at the top of the page,\n select the project that contains your private pool.\n\n 3. Click **Grant access**.\n\n 4. Enter the following principal and role settings:\n\n - **Add principals**: Enter email address of the service account that\n you are using with your trigger.\n\n - **Assign roles**: Select the Cloud Build WorkerPool User role.\n\n 5. Click **Save** to save your new IAM permissions.\n\n ### gcloud\n\n **To add the build service account from the trigger\n project to the workerpool project with the cloudbuild.workerPoolUser role**: \n\n gcloud projects add-iam-policy-binding \u003cvar translate=\"no\"\u003ePRIVATEPOOL_PROJECT_ID\u003c/var\u003e \\\n --member=serviceAccount:\u003cvar translate=\"no\"\u003eSERVICE_ACCOUNT\u003c/var\u003e \\\n --role=roles/cloudbuild.workerPoolUser\n\n Replace the placeholder values in the command above with the following:\n - \u003cvar translate=\"no\"\u003ePRIVATEPOOL_PROJECT_ID\u003c/var\u003e is the ID of the project with the private pool running the build.\n - \u003cvar translate=\"no\"\u003eSERVICE_ACCOUNT\u003c/var\u003e is the email of the service account you are using with the trigger executing the build.\n\nRunning builds\n--------------\n\nYou can submit builds from the same Google Cloud project where you created the\nprivate pool or from a different Google Cloud project. You can specify\nthe private pool either in your build config file or direcly in the\n`gcloud` command:\n\n**Specifying the private pool in the build config file:**\n\n1. In your [Cloud Build config file](/build/docs/build-config),\n add a `pool` option and specify the full resource name of the private\n pool to run the build:\n\n ### YAML\n\n steps:\n - name: 'bash'\n args: ['echo', 'I am running in a private pool!']\n options:\n pool:\n name: 'projects/\u003cvar translate=\"no\"\u003ePRIVATEPOOL_PROJECT_ID\u003c/var\u003e/locations/\u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e/workerPools/\u003cvar translate=\"no\"\u003ePRIVATEPOOL_ID\u003c/var\u003e'\n\n ### JSON\n\n {\n \"steps\": [\n {\n \"name\": \"bash\",\n \"args\": [\n \"echo\",\n \"I am running in a private pool!\"\n ]\n }\n ],\n \"options\": {\n \"pool\" : {\n \"name\" : \"projects/\u003cvar translate=\"no\"\u003ePRIVATEPOOL_PROJECT_ID\u003c/var\u003e/locations/\u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e/workerPools/\u003cvar translate=\"no\"\u003ePRIVATEPOOL_ID\u003c/var\u003e\"\n }\n }\n }\n\n Replace the placeholder values in the config file above with the following:\n - \u003cvar translate=\"no\"\u003ePRIVATEPOOL_PROJECT_ID\u003c/var\u003e: the Google Cloud project where your private pool is located.\n - \u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e: the region where you created your private pool.\n - \u003cvar translate=\"no\"\u003ePRIVATEPOOL_ID\u003c/var\u003e: the unique private pool ID that you specified when creating the private pool.\n2. Use the build config file created above to run your build via [`gcloud` or API](/build/docs/running-builds/start-build-manually)\n or using [triggers](/build/docs/running-builds/automate-builds). If your\n instance is hosted on-premises, Cloud Build also provides\n trigger functionality support for several external\n source code management systems such as [GitHub Enterprise](/build/docs/automating-builds/build-repos-from-github-enterprise)\n or [Bitbucket Server](/build/docs/automating-builds/build-repos-from-bitbucket-server).\n\n**Specifying the private pool in the gcloud command:**\n\nYou can specify the private pool in the `gcloud` command instead of in the\nbuild config file. For example, consider you have the following build config\nfile: \n\n### YAML\n\n steps:\n - name: 'bash'\n args: ['echo', 'I am running in a private pool!']\n\n### JSON\n\n {\n \"steps\": [\n {\n \"name\": \"bash\",\n \"args\": [\n \"echo\",\n \"I am running in a private pool!\"\n ]\n }\n ],\n }\n\nThe following command builds using the build config file and specifies the worker\npool in the command: \n\n gcloud builds submit --config=\u003cvar translate=\"no\"\u003eCONFIG_FILE\u003c/var\u003e\n --worker-pool=projects/\u003cvar translate=\"no\"\u003ePRIVATEPOOL_PROJECT_ID\u003c/var\u003e/locations/\u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e/workerPools/\u003cvar translate=\"no\"\u003ePRIVATEPOOL_ID\u003c/var\u003e\n\nReplace the placeholder values in the above commands with the following:\n\n- \u003cvar translate=\"no\"\u003eCONFIG_FILE\u003c/var\u003e: path to your build config file.\n- \u003cvar translate=\"no\"\u003ePRIVATEPOOL_ID\u003c/var\u003e: the unique private pool ID that you specified when creating the private pool.\n- \u003cvar translate=\"no\"\u003ePRIVATEPOOL_PROJECT_ID\u003c/var\u003e: the Google Cloud project where your private pool is located.\n- \u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e: the region where you created your private pool.\n\nWhat's next?\n------------\n\n- Learn how to [create and manage private pools](/build/docs/private-pools/create-manage-private-pools).\n- Learn how to [use VPC Service Controls with private pools](/build/docs/private-pools/using-vpc-service-controls).\n- Learn how to [create and manage build triggers](/build/docs/automating-builds/create-manage-triggers).\n- Learn how to [build repositories from GitHub Enterprise](/build/docs/automating-builds/build-repos-from-github-enterprise).\n- Learn how to [build repositories from Bitbucket Server](/build/docs/automating-builds/build-repos-from-bitbucket-server)."]]