Building repositories from GitHub Stay organized with collections Save and categorize content based on your preferences.
Cloud Build lets you create triggers to build fromrepositories hosted onGitHub.You can execute builds in response to events such as commit pushes ormerge requests associated with your GitHub repository.
This page explains how you can enable build triggers for aGitHub instance. For more information, seeCloud Build triggers andCloud Build repositories.
Before you begin
Follow the instructions toconnect to a GitHub host.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.enablepermission.Learn how to grant roles.
To create a trigger for a GitHub repository, you must have a connectionbetween Google Cloud and your repository. To create a connection through theGitHub app in Google Cloud, seeConnect to a GitHub repository.
Create a GitHub trigger
This section explains how you can create a trigger and link it to yourGitHub installation.
Google Cloud console
To create GitHub triggers using the Google Cloud console, do the following:
Open theTriggers page in the Google Cloud console.
Select your Google Cloud project and clickOpen.
ClickCreate trigger.
Enter the following trigger settings:
Name: Enter a name for your trigger.
Region: Select theregion for your trigger.
- If the build config file associated with the trigger specifies aprivate pool, thenCloud Build uses the private pool to run your build. In thiscase, the region you specify in your trigger must match the regionwhere you created your private pool.
- If the build config file associated with the triggerdoesn'tspecify a private pool, then Cloud Build uses the defaultpool 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 toa particular branch.
Push new tag: Set your trigger to start a build on commits thatcontain a particular tag.
Pull request: Set your trigger to start a buildon commits to a pull request.
Note: Running builds initiated by a GitHub App pull request triggerare canceled when you close the pull request associated withyour build. Running builds and builds that have not been startedyet won't be canceled when merging a pull request.
Source: Configure information about your GitHub repository:
Repository service: Select Cloud Build.
Repository generation: Select1st generation as your source.
Repository: From the list of available repositories, select therepository.
Branch orTag: Specify a regular expression with the branch ortag value to match. For information on acceptable regular expression syntax,seeRE2 syntax.
Comment control: If you selectedPull requestas yourEvent, choose one of the following options tocontrol whether a build is automatically executed by the trigger:
Required except for owners and collaborators: When a pullrequest is created or updated by a repository owner or collaborator,builds are automatically executed by the trigger. If an externalcontributor initiates the action, builds are executed only afteran owner or collaborator comments
/gcbrunon the pull request.Required: When a pull request is created or updated by anycontributor, builds are executed only after an owner orcollaborator comments
/gcbrunon the pull request. Buildsare executed each time a change to a pull request is made.Not required: When a pull request is created or updated by anycontributor, builds are automatically be executed by triggers.
Configuration: Select the build config file located inyour remote repository or create an inline build config file touse 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.yamlorDockerfilein your repository. - Cloud Build configuration file (yaml or json):Use a build config file for your configuration.
- Dockerfile: Use a
Dockerfilefor your configuration. - Buildpacks: Usebuildpacks for your configuration.
- Autodetected: Cloud Build autodetects your configuration type if you have a
Location: Specify the location for your configuration.
- Repository: If your config file is located in yourremote repository, provide the location of yourbuild config file or the
Dockerfiledirectory and a name for the resulting image. If your configurationis aDockerfile, you can optionally provide a timeout for your build.When you've provided theDockerfileand image name, you'll see apreview of thedocker buildcommand that your build will execute. - Inline: If you selectedCloud Build configuration file (yaml or json) asyour configuration option, you can specify your build configinline. ClickOpen Editor to write your build config file in theGoogle Cloud console using YAML or JSON syntax. ClickDone tosave your build config.
Dockerfile.- Repository: If your config file is located in yourremote repository, provide the location of yourbuild config file or the
- Type: Select the type of configuration to use for your build.
Substitution variables (optional): If you selected the Cloud Buildconfig file as your build config option, you can choose to define trigger-specificsubstitution variables using this field. For example, say you're creatingmultiple 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 configfile and then use this field to define substitution variables specifying whichenvironment this trigger should deploy to. For information on specifyingsubstitution values in build config files, seeSubstituting variable values.
Build logs (optional): Check the box to send build logs to GitHub. To learn how to view build logs, seeViewing build logs.
Service account: Select the service account to use when invokingyour trigger. If your organization policy allows using the legacyCloud Build service account, you can leave this blank to usethe legacy service account. Otherwise, you must select the specificservice account to use, even if it's the Compute Engine defaultservice account.
Note: Only the service account specified on your trigger is used forbuilds executed by triggers. If you specified a service account in yourbuild config, it's ignored during build execution when using triggers.
ClickCreate to save your build trigger.
To create GitHub triggers usinggcloud commands, see thegcloudcommands forCreating a build trigger.
gcloud CLI
To create GitHub triggers usinggcloud commands, run the followingcommand:
gcloudalphabuildstriggerscreatedeveloper-connect--name=TRIGGER_NAME\--git-repository-link=projects/PROJECT_ID/locations/REGION/connections/CONNECTION_NAME/gitRepositoryLinks/REPO_NAME\--branch-pattern=BRANCH_PATTERN#or--tag-pattern=TAG_PATTERN\--build-config=BUILD_CONFIG_FILE\--region=REGION\--service-account=SERVICE-ACCOUNTWhere:
- TRIGGER_NAME is the name of your trigger.
- PROJECT_ID is your Google Cloud project ID.
- REGION is theregion of your trigger.
- CONNECTION_NAME is the name of your GitHub connection.
- GIT_REPOSITORY_LINK is the link to your Git repository.
- BRANCH_PATTERN is the branch name in yourrepository to invoke the build on.
- TAG_PATTERN is the tag name in yourrepository to invoke the build on.
- BUILD_CONFIG_FILE is the path to your buildconfiguration file.
- SERVICE-ACCOUNT is the service account to usefor trigger and build operations.
API
To create a GitHub trigger with the API, use thefollowing JSON template:
{"filename":"cloudbuild.yaml","name":"TRIGGER_NAME","description":"TRIGGER_DESCRIPTION","serviceAccount":"SERVICE_ACCOUNT","github":{"owner":"OWNER","name":"REPO_NAME","push":{"branch":".*"},},"include_build_logs":include-build-logs-value}Where:
- TRIGGER_NAME is a name for the trigger.
- TRIGGER_DESCRIPTION is a description for the trigger.
- SERVICE_ACCOUNT is the service account to usefor trigger and build operations.
- OWNER is the owner of the GitHub repository.
- REPO_NAME is the name of the GitHub repository.
- include-build-logs-value is the value of theoptional
include_build_logsfield. If this field has a value ofINCLUDE_BUILD_LOGS_SPECIFIED, then build logs are shown onyour repository.
Enter the followingcurl command in your terminal:
curl-XPOST-H"Authorization: Bearer "$(gcloudauthprint-access-token)-H"Content-Type: application/json; charset=utf-8"-H"x-goog-user-project:PROJECT_NUMBER"https://cloudbuild.googleapis.com/v1/projects/PROJECT_ID/triggers-d@trigger.jsonWhere:
- PROJECT_NUMBER is your Google Cloud project number.
- PROJECT_ID is your Google Cloud project ID.
Build and view your changes
To build using GitHub triggers, you'llneed to push and commit changes to your connected source repositoryor configure your build on pull requests. Once you have checkedin your changes, Cloud Build willbuild your code.
To view your build changes on GitHub, go to theChecks tab in your repository.

You'll see that Cloud Build has built your changes. You'll also seeother build details such as the time it took to build your code and the build ID.
To view your build changes in Cloud Build, clickView more details on Google Cloud Build. TheBuild details page in Google Cloud console opens where you can see build information such asstatus, logs, and build steps.
Different types of GitHub-based triggers
If your source code is in GitHub, Cloud Build provides two ways bywhich you can automatically execute builds. This section explains the twoGitHub-based triggers and compares their features.
GitHub legacy triggers: When you create a GitHub legacy trigger, Cloud Buildmirrors your GitHub repository in Cloud Source Repositories and uses themirrored repository for all its operations. You cancreate and manage GitHub triggersusing the Google Cloud console.
Note: If you are using GitHub legacy triggers, you will need to grantaccess to individual organizations withGitHub to use GitHub legacy triggers.GitHub triggers: This type of trigger uses the Cloud BuildGitHub app to configure and authenticate to GitHub. GitHub triggers allowyou to automatically start builds on Git pushes and pull requests and viewbuild results on GitHub and the Google Cloud console. You can create and manageGitHub triggers using Google Cloud console or the Cloud Build API,as described on this page.
GitHub Enterprise triggers: This type of trigger lets you invokebuilds in response to commits or pull requests on a GitHub Enterpriseinstance. You canbuild repositories from GitHub Enterprise using the Google Cloud console or the Cloud Build API.
The following table compares GitHub legacy triggers, GitHub triggers,and GitHub Enterprise triggers:
| Feature | GitHub legacy triggers | GitHub triggers | GitHub Enterprise triggers |
|---|---|---|---|
| Execute builds on pushes to the source code | Yes | Yes | Yes |
| Execute builds on pull requests | No | Yes | Yes |
| Create trigger using Google Cloud console | Yes | Yes | Yes |
| Create trigger using the Cloud Build API | No | Yes | Yes |
| Create trigger using the Cloud Build GitHub app | No | Yes | Yes |
| View build status on Google Cloud console | Yes | Yes | Yes |
| View build status on GitHub | No | Yes | Yes |
Data sharing
The data sent to GitHub from Cloud Build helps you identify triggersby name and see build results on GitHub.
The following data is currently shared between Cloud Build and GitHub:
- Cloud project ID
- Trigger name
- Build logs
If you created triggers prior to August 2020, data sharing may not be enabledfor your project. You can enable data sharing for all GitHub triggers inyour project by clickingEnable on theCloud Build Data sharing tab.
If you haverequired status checks enabled for a GitHub repository, enabling data sharing may temporarily breakstatus checks. You can adjust status check configurations to look foryour trigger name by:
- Disabling any Cloud Build-specific required checks on the GitHub repository
- Ensuring that data sharing is enabled in Cloud Build
- Executing a new build in Cloud Build that posts statuses to your repository
- Re-enabling required status checks, selecting trigger name
What's next
- Learn how tocreate and manage build triggers.
- Learn how toperform blue-green deployments on Compute Engine.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2026-02-19 UTC.