Text of docs.cloud.google.com › build › docs › automating-builds › github › build-repos-from-gi… as Styx crawled it on Nov 19, 2026. The page may have changed since. Only its words are kept, without pictures or layout, and only the first part of a long page.

Open the live page

Building repositories from GitHub | Google Cloud Documentation

Skip to main content Console English Deutsch Español Español – América Latina Français Indonesia Italiano Português Português – Brasil עברית 中文 – 简体 中文 – 繁體 日本語 한국어 Sign in Cloud Build Start free Home Documentation Application development Cloud Build Guides Building repositories from GitHub Stay organized with collections Save and categorize content based on your preferences.

Cloud Build lets you create triggers to build from repositories hosted on GitHub . You can execute builds in response to events such as commit pushes or merge requests associated with your GitHub repository. This page explains how you can enable build triggers for a GitHub instance. For more information, see Cloud Build triggers and Cloud Build repositories . Before you begin Follow the instructions to connect to a GitHub host .

Enable the Cloud Build API, if it is not already enabled. Roles required to enable APIs To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role ( roles/owner ). Otherwise, you can get this permission through the Service Usage Admin role ( roles/serviceusage.serviceUsageAdmin ). Learn how to grant roles . Enable the API To create a trigger for a GitHub repository, you must have a connection between Google Cloud and your repository.

To create a connection through the GitHub app in Google Cloud, see Connect to a GitHub repository . Create a GitHub trigger This section explains how you can create a trigger and link it to your GitHub installation. Google Cloud console To create GitHub triggers using the Google Cloud console, do the following: Open the Triggers page in the Google Cloud console. Open the Triggers page Select your Google Cloud project and click Open .

Click Create trigger . Enter the following trigger settings: Name : Enter a name for your trigger. Region : Select the region for your trigger. If the build config file associated with the trigger specifies a private pool , then Cloud Build uses the private pool to run your build. In this case, the region you specify in your trigger must match the region where you created your private pool. If the build config file associated with the trigger doesn't specify a private pool, then Cloud Build uses the default pool to run your build in the same region as your trigger.

Description (optional): Enter a description for your trigger. Event : Select the repository event to invoke your trigger. Push to a branch : Set your trigger to start a build on commits to a particular branch. Push new tag : Set your trigger to start a build on commits that contain a particular tag. Pull request : Set your trigger to start a build on commits to a pull request. Source : Configure information about your GitHub repository: Repository service : Select Cloud Build.

Repository generation : Select 2nd generation as your source. Repository : From the list of available repositories, select the repository. Branch or Tag : Specify a regular expression with the branch or tag value to match. For information on acceptable regular expression syntax, see RE2 syntax . Comment control : If you selected Pull request as your Event , choose one of the following options to control whether a build is automatically executed by the trigger: Required except for owners and collaborators : When a pull request is created or updated by a repository owner or collaborator, builds are automatically executed by the trigger.

If an external contributor initiates the action, builds are executed only after an owner or collaborator comments /gcbrun on the pull request. Required : When a pull request is created or updated by any contributor, builds are executed only after an owner or collaborator comments /gcbrun on the pull request. Builds are executed each time a change to a pull request is made. Not required : When a pull request is created or updated by any contributor, builds are automatically be executed by triggers.

Configuration : Select the build config file located in your remote repository or create an inline build config file to use for your build. Type : Select the type of configuration to use for your build. Autodetected : Cloud Build autodetects your configuration type if you have a cloudbuild.yaml or Dockerfile in your repository. Cloud Build configuration file (yaml or json) : Use a build config file for your configuration.

Dockerfile : Use a Dockerfile for your configuration. Buildpacks : Use buildpacks for your configuration. Location : Specify the location for your configuration. Repository : If your config file is located in your remote repository, provide the location of your build config file or the Dockerfile directory and a name for the resulting image. If your configuration is a Dockerfile , you can optionally provide a timeout for your build.

When you've provided the Dockerfile and image name, you'll see a preview of the docker build command that your build will execute. Inline : If you selected Cloud Build configuration file (yaml or json) as your configuration option, you can specify your build config inline. Click Open Editor to write your build config file in the Google Cloud console using YAML or JSON syntax. Click Done to save your build config. Substitution variables (optional): If you selected the Cloud Build config file as your build config option, you can choose to define trigger-specific substitution variables using this field.

For example, say you're creating multiple triggers where each trigger deploys your app to a specific environment. You can specify that your app is deployed to an environment in your build config file and then use this field to define substitution variables specifying which environment this trigger should deploy to. For information on specifying substitution values in build config files, see Substituting variable values .

Build logs (optional): Check the box to send build logs to GitHub. To learn how to view build logs, see Viewing build logs . Service account : Select the service account to use when invoking your trigger. If your organization policy allows using the legacy Cloud Build service account, you can leave this blank to use the legacy service account. Otherwise, you must select the specific service account to use, even if it's the Compute Engine default service account.

Click Create to save your build trigger. To create GitHub triggers using gcloud commands, see the gcloud commands for Creating a build trigger . gcloud CLI To create GitHub triggers using gcloud commands, run the following command: gcloud builds triggers create github \ -- name = TRIGGER_NAME \ -- repository = projects / PROJECT_ID / locations / REGION / connections / CONNECTION_NAME / repositories / REPO_NAME \ -- branch - pattern = BRANCH_PATTERN # or -- tag - pattern = TAG_PATTERN \ -- build - config = BUILD_CONFIG_FILE \ -- region = REGION \ -- service - account = SERVICE - ACCOUNT Where: TRIGGER_NAME is the name of your trigger.

PROJECT_ID is your Google Cloud project ID. REGION is the region of your trigger. CONNECTION_NAME is the name of your GitHub connection. REPO_NAME is the name of your repository BRANCH_PATTERN is the branch name in your repository to invoke the build on. TAG_PATTERN is the tag name in your repository to invoke the build on. BUILD_CONFIG_FILE is the path to your build configuration file. SERVICE-ACCOUNT is the service account to use for trigger and build operations.

API To create a GitHub trigger with the API, use the following JSON template: { "filename" : "cloudbuild.yaml" , "name" : "curl-trigger" , "description" : "curl trigger&q uot; , "repository_event_config" : { "repository" : "REPO_NAME" , "repository_t ype" : "GITHUB" , // Field fi lter must be only one of the following: "pullRequest" : "PULL_REQUEST_FILTER" , "push" : "PUSH_FILTER" } } Where: " REPO_NAME " is the name of the repository connection that you configured in Cloud Buil

The rest of this page is on the live site.