Cloud Build uses build triggers to enable CI/CD automation. You can configure triggers to listen for incoming events, such as when a new commit is pushed to a repository or when a pull request is initiated, and then automatically execute a build when new events come in. You can also configure triggers to build code on any changes to your source repository or only on changes that match certain criteria.
This page provides an overview of each trigger type and capabilities associated with triggers.
Repository event triggers
Cloud Build enables you to automatically execute builds on repository events such as pushes or pull requests. You can connect external repositories, such as repositories in GitHub or Bitbucket, to Cloud Build or use code in Cloud Source Repositories for your builds. While you can connect any source repository to Cloud Build, Cloud Build provides specific repository event triggers you can can use to easily integrate specific source code management systems (SCMs). This section discusses available repository event triggers.
You can create GitHub triggers to automatically execute builds in response to repository events, such as pushes or pull requests. You can view the trigger's build status on GitHub and Cloud Console. You can also use the Cloud Build GitHub app to connect and build code in GitHub. To learn more, see Building repositories from GitHub.
GitHub Enterprise triggers
You can create triggers for repositories hosted on a GitHub Enterprise instance, including instances hosted in an on-premises environment and not reachable over a public internet connection. GitHub Enterprise triggers can be used to execute builds in response to pushes or pull requests from a GitHub Enterprise instance. To learn more, see Building repositories from GitHub Enterprise.
You can create manual triggers to execute builds manually and override defined substitution variable values at invocation time prior to executing a build. You can also configure manual triggers to run on a schedule. To learn more, see Creating manual triggers.
You can create Pub/Sub triggers to execute builds in response to
any message published over Pub/Sub. For example, you
can use Pub/Sub triggers for building in response to image
pushes to Artifact Registry. In this case, you can configure your trigger
to use filters to execute a build only if the pushed image matches a
specific tag, such as
prod. Additionally, Pub/Sub
triggers can be configured to subscribe to any Pub/Sub topic. To
learn more, see
Creating Pub/Sub triggers.
You can create webhook triggers to execute builds in response to webhooks. Webhook events sent to a custom URL enable you to directly connect external systems and external source code management systems (SCMs), such as Bitbucket.com, Bitbucket Server, or GitLab, to Cloud Build. When creating webhook triggers, you can also define your build configuration inline on your trigger to control which repositories your trigger clones during build time rather than explicitly specifying a source. To learn more, see Creating webhook triggers. Additionally, to learn to use webhook triggers to build repositories from specific SCMs, see Building repositories from Bitbucket Server, Building repositories from Bitbucket Cloud, and Building repositories from GitLab.
Cloud Build triggers provide capabilities that give you fine-grained control over how a build is executed. This section discusses various capabilities associated with triggers.
Scheduling manual triggers
You can schedule manual triggers to automatically execute builds on a pre-defined schedule. For example, you may want to configure a scheduled trigger to run a build every Saturday at 6:00 AM. To schedule builds, you can create a manual trigger and invoke the trigger using Cloud Scheduler. To learn more, see Creating scheduled triggers.
Cloud Build uses
Common Expression Language (CEL) with the variable,
build, on fields
listed in the Build
resource to access fields associated with your build event such as
your trigger ID, image list, or substitution values. You can use the
string to filter build events in your build config file using
any field listed in the Build
resource. To learn more, see
Use CEL to filter build events
You can specify substitution variables in your build configuration file to substitute specific values at build time. For example, you may want to use substitution variables if a value is not known until build time or if you want to re-use an existing build request with different variables. Cloud Build provides default substitutions you can use for builds invoked by triggers, such as variables mapping to your trigger name or repository name. You can also define your own substitution variables. To learn more, see Substituting variable values.
Bash parameter expansions
You can apply bash parameter expansions to substitution variable values. Bash parameter expansions allow you to manipulate strings associated with existing variables. For example, you can use bash parameter expansions to capitalize letters or replace a substring. To learn more, see Bash parameter expansions.
You can store part of your trigger's event payload as a substitution variable by using payload bindings. Variables associated with a payload are referred to as bindings and are available for builds invoked by both push and pull events. You can use bindings to access additional data related to your build, such as the author of a pull request. To learn more, see Payload bindings.
You can configure triggers to not immediately execute a build, but instead mark a build as pending until approved. If a user with permissions approves a pending build, the build starts. If the approval is denied, the build doesn't start. To learn how to configure triggers that require approval, see Approving builds.
Build status notifications
You can configure Cloud Build notifiers to listen to build
event updates from on the Pub/Sub
Notifers can also filter messages received by the topic and send
messages to your desired service. Cloud Build provides
and maintains deployable notifier images in the
You can configure notifications using a Cloud Build notifier,
such as BigQuery,
create your own notifier.
- Learn how to create and manage build triggers.