Run builds in a private pool (original) (raw)

This document explains how to run builds in private pools. If you're new to private pools, read the Private pools overview.

Before you begin

gcloud config set project BUILD_ORIGIN_PROJECT_ID  

IAM permissions

Console

  1. Open the IAM page in the Google Cloud console.
    Open the IAM Permissions page
  2. In the project selector drop-down menu at the top of the page, select the project that contains your private pool.
  3. Click Grant access.
  4. Enter the following principal and role settings:
    • Add principals: Enter email address of the service account that you are using with your trigger.
    • Assign roles: Select the Cloud Build WorkerPool User role.
  5. Click Save to save your new IAM permissions.

gcloud

To add the build service account from the trigger project to the workerpool project with the cloudbuild.workerPoolUser role:

  gcloud projects add-iam-policy-binding PRIVATEPOOL_PROJECT_ID \  
      --member=serviceAccount:SERVICE_ACCOUNT \  
      --role=roles/cloudbuild.workerPoolUser  

Replace the placeholder values in the command above with the following:

Running builds

You can submit builds from the same Google Cloud project where you created the private pool or from a different Google Cloud project. You can specify the private pool either in your build config file or direcly in thegcloud command:

Specifying the private pool in the build config file:

  1. In your Cloud Build config file, add a pool option and specify the full resource name of the private pool to run the build:

YAML

steps:  
- name: 'bash'  
  args: ['echo', 'I am running in a private pool!']  
options:  
  pool:  
    name: 'projects/PRIVATEPOOL_PROJECT_ID/locations/REGION/workerPools/PRIVATEPOOL_ID'  

JSON

{  
  "steps": [  
  {  
    "name": "bash",  
    "args": [  
      "echo",  
      "I am running in a private pool!"  
    ]  
  }  
  ],  
  "options": {  
    "pool" : {  
      "name" : "projects/PRIVATEPOOL_PROJECT_ID/locations/REGION/workerPools/PRIVATEPOOL_ID"  
    }  
  }  
}  

Replace the placeholder values in the config file above with the following:

  1. Use the build config file created above to run your build via gcloud or APIor using triggers. If your instance is hosted on-premises, Cloud Build also provides trigger functionality support for several external source code management systems such as GitHub Enterpriseor Bitbucket Server.

Specifying the private pool in the gcloud command:

You can specify the private pool in the gcloud command instead of in the build config file. For example, consider you have the following build config file:

YAML

  steps:
  - name: 'bash'
    args: ['echo', 'I am running in a private pool!']

JSON

  {
    "steps": [
    {
      "name": "bash",
      "args": [
        "echo",
        "I am running in a private pool!"
      ]
    }
    ],
  }

The following command builds using the build config file and specifies the worker pool in the command:

gcloud builds submit --config=CONFIG_FILE
  --worker-pool=projects/PRIVATEPOOL_PROJECT_ID/locations/REGION/workerPools/PRIVATEPOOL_ID

Replace the placeholder values in the above commands with the following:

What's next?