Building repositories from GitHub

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.enable permission.Learn how to grant roles.

    Enable the API

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:

  1. Open theTriggers page in the Google Cloud console.

    Open the Triggers page

  2. Select your Google Cloud project and clickOpen.

  3. ClickCreate trigger.

  4. Enter the following trigger settings:

  5. 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-ACCOUNT

Where:

  • 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 theoptionalinclude_build_logs field. 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.json

Where:

  • 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.

Screenshot of the conversation tab

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:

FeatureGitHub legacy triggersGitHub triggersGitHub Enterprise triggers
Execute builds on pushes to the source codeYesYesYes
Execute builds on pull requestsNoYesYes
Create trigger using Google Cloud consoleYesYesYes
Create trigger using the Cloud Build APINoYesYes
Create trigger using the Cloud Build GitHub appNoYesYes
View build status on Google Cloud consoleYesYesYes
View build status on GitHubNoYesYes

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
Note: Build logs are only shared if you configure your trigger to send 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
Note: Enabling data sharing for a project is not reversible.

What's next

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.