在私人集區中建立及執行建構作業
本頁說明如何建立連線至服務生產端網路的 Cloud Build 私人集區,並在私人集區中執行建構作業。
服務供應商網路是代管私人集區的網路。根據預設,私人集區會設定為使用服務供應商網路,為建構環境提供下列項目:
- 可設定的機器類型
- 可設定的磁碟大小
- 存取公開網際網路中的資源,例如存放區或註冊資料庫中的資源
如要直接在 Cloud Shell 編輯器中按照逐步指南操作,請按一下「Guide me」(逐步引導):
事前準備
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator
(
roles/resourcemanager.projectCreator
), which contains theresourcemanager.projects.create
permission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Cloud Build API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin
), which contains theserviceusage.services.enable
permission. Learn how to grant roles. -
Install the Google Cloud CLI.
-
如果您使用外部識別資訊提供者 (IdP),請先 使用聯合身分登入 gcloud CLI。
-
如要初始化 gcloud CLI,請執行下列指令:
gcloud init
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator
(
roles/resourcemanager.projectCreator
), which contains theresourcemanager.projects.create
permission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Cloud Build API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin
), which contains theserviceusage.services.enable
permission. Learn how to grant roles. -
Install the Google Cloud CLI.
-
如果您使用外部識別資訊提供者 (IdP),請先 使用聯合身分登入 gcloud CLI。
-
如要初始化 gcloud CLI,請執行下列指令:
gcloud init
在 Google Cloud 控制台中,開啟「Cloud Build Worker pool」(Cloud Build 工作站集區) 分頁:
按一下
「Create」(建立) 。在「Create private pool」(建立私人集區) 面板中輸入下列設定:
在
「Name」(名稱) 欄位中輸入my-first-privatepool
。在
「Region」(區域) 欄位中選取「us-central1
」。在
「Machine type」(機器類型) 欄位中選取「e2-standard-2
」。在
「Available disk size」(可用磁碟大小) 欄位中輸入800
。將
「Network project number」(網路專案編號) 欄位留空。將
「Network」(網路) 欄位留空。確認已選取
「Assign external IPs」(指派外部 IP) 。
開啟終端機視窗。
建立名為
quickstart-private-pool
的新目錄,然後前往該目錄:mkdir quickstart-private-pool cd quickstart-private-pool
建立名為
cloudbuild.yaml
的檔案,並在當中加入下列內容:steps: - name: "bash" script: echo "I am running in a private pool!" options: pool: name: "projects/$PROJECT_ID/locations/us-central1/workerPools/my-first-privatepool"
使用建構設定檔展開建構作業:
gcloud builds submit
在 Google Cloud 控制台中開啟「建構記錄」頁面。
在
畫面會顯示您在私人集區中執行的建構作業。「Region」(區域) 下拉式方塊中選取「us-central1」。按一下建構作業即可查看建構作業詳細資料,例如建構作業摘要及構件。
在 Google Cloud 控制台中開啟「Worker pool」(工作站集區) 頁面:
在您的私人集區那一列中,點選「垃圾桶」圖示。
在「Delete private pool?」(要刪除私人集區嗎?) 彈出式方塊中點選「Delete」(刪除)。
- 瞭解如何建立私人虛擬私有雲對接連線。
- 進一步瞭解私人集區。
建立私人集區
按一下
建立私人集區會花費一些時間。私人集區建立完成後,就會列在「Worker pool」(工作站集區) 分頁中。

在私人集區中執行建構作業
建構完成時,畫面會顯示類似以下的輸出:
I am running in a private pool!
PUSH
DONE
------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------
ID CREATE_TIME DURATION SOURCE IMAGES STATUS
5df45735-6414-40b7-9e10-e6d2023c8cea 2020-08-31T13:16:18+00:00 10S gs://private-pool-test_cloudbuild/source/1598879777.206444- 58901ecbd14e431f8cdacc85d5dd0fc3.tgz - SUCCESS
查看建構作業詳細資料

清除所用資源
如要避免系統向您的 Google Cloud 帳戶收取本頁所用資源的費用,請按照下列步驟操作。
您在本快速入門導覽課程中建立的私人集區現在已刪除。如果無法透過「Worker pool」(工作站集區) 頁面刪除私人集區,您可能必須重新整理畫面。