{"steps":[{"name":"bash","args":["echo","I am running in a private pool!"]}],"options":{"pool":{"name":"projects/PRIVATEPOOL_PROJECT_ID/locations/REGION/workerPools/PRIVATEPOOL_ID"}}}
[[["易于理解","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\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)."]]