This page explains how to use Cloud Build to automate builds.
Cloud Build uses build triggers to enable CI/CD automations. 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 invoke a build when new events come in.
You will create a trigger and configure that trigger to invoke a build anytime you push a change to a GitHub repository.
To follow step-by-step guidance for this task directly in the Cloud Shell Editor, click Guide me:
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
roles/resourcemanager.projectCreator), which contains the
resourcemanager.projects.create permission. Learn how to grant
roles.
If you're using an existing project for this guide, verify that you have the permissions required to complete this guide. If you created a new project, then you already have the required permissions.
Verify that billing is enabled for your Google Cloud project.
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 the serviceusage.services.enable permission. Learn how to grant
roles.
Install the Google Cloud CLI.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
To initialize the gcloud CLI, run the following command:
gcloud initIn the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
roles/resourcemanager.projectCreator), which contains the
resourcemanager.projects.create permission. Learn how to grant
roles.
If you're using an existing project for this guide, verify that you have the permissions required to complete this guide. If you created a new project, then you already have the required permissions.
Verify that billing is enabled for your Google Cloud project.
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 the serviceusage.services.enable permission. Learn how to grant
roles.
Install the Google Cloud CLI.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
To initialize the gcloud CLI, run the following command:
gcloud initIf you don't have one already, create an account on GitHub.
If you have two-factor authentication set up on GitHub, create a personal access token to use in place of a GitHub password with the command line.
To get the permissions that you need to automate builds by using Cloud Build, ask your administrator to grant you the following IAM roles on the Cloud Build service account:
roles/cloudbuild.builds.editor)roles/storage.objectUser)roles/storage.bucketViewer)roles/cloudbuild.connectionAdmin)For more information about granting roles, see Manage access to projects, folders, and organizations.
You might also be able to get the required permissions through custom roles or other predefined roles.
If you don't have one already, create an account on GitHub.
If you have two-factor authentication set up on GitHub, create a personal access token to use in place of a GitHub password with the command line.
Fork the cloud-build-samples repository to your own GitHub account:
Go to the Cloud Build cloud-build-samples repository.
Click on the Fork icon on the top-right corner of the page.
Click on the GitHub user account you want to fork the repository to.
You will automatically be redirected to the page with your
forked version of the cloud-build-samples repository.
Open a terminal in your local environment.
Clone the forked repository by running the following command, where GITHUB_USERNAME is the username for your GitHub account:
git clone https://github.com/GITHUB_USERNAME/cloud-build-samples.gitcloud-build-samples repository to Cloud Build.
In the Google Cloud console navigation menu, click Cloud Build > Triggers.
Select your project and click Open.
Click
Under Select source, select
Click
Authenticate your GitHub account.
In the Select repository section, select the username of your
In the GitHub account list, click +Add.
You will see a pop-up to install the Cloud Build GitHub app.
Click on your GitHub username.
Click Only certain repositories to install the Cloud Build GitHub app on certain repositories.
On the drop-down menu, select GITHUB_USERNAME/cloud-build-samples, where GITHUB_USERNAME is the username for your GitHub account.
Click Install.
You may be asked to enter the password associated with your GitHub account before proceeding.
Following the installation of the Cloud Build GitHub app, you will now be able to see your username in the drop-down menu on the GitHub account field. Select your username.
Under
Click the checkmark to agree to terms and conditions for trigger connection.
Click
Click
Open the Triggers page in the Google Cloud console:
Select your project from the project selector drop-down menu at the top of the page.
Click Open.
On the Triggers page, click
On the Create trigger page, enter the following settings:
Name: Enter hello-world-trigger as the name of
your trigger.
Event: Select
cloud-build-samples repository as your
source, which contains your source code and your build config file.
Build Configuration: Choose
quickstart-automate/cloudbuild.yaml.
Click
In this section, you will commit a change to your cloned cloud-build-samples
repository on your own GitHub account.
In your terminal, navigate to the quickstart-automate directory:
cd cloud-build-samples/quickstart-automateOpen the main.go file and update the line containing "Hello, world!"
to "Hello, universe!"
package main import ( "fmt" ) func main() { fmt.Println("Hello, universe!") }
Review cloudbuild.yamlgolang image from Docker Hub
to build and run the main.go file.
steps: - name: golang script: go run quickstart-automate/main.go
Navigate back to the root directory of your repository:
cd ..Commit your changes to GitHub by running the following commands:
git add quickstart-automate/main.go
git commit -m "update text"
git pushYou may be prompted to enter your credentials when pushing code to your repository. If prompted, enter your username and password or an authentication token.
You have now pushed a change to your repository. Your push will result in an automatic build by your trigger.
In the Google Cloud console navigation menu, click Cloud Build > History.
Select your project and click Open.
You will see the Build history page:
In the
On the Build details page, click
You will see an output similar to the following:
To view the build log, click the
You have successfully invoked a Cloud Build build using a trigger and viewed the build details.
To avoid incurring charges to your Google Cloud account for the resources used on this page, follow these steps.
In the Google Cloud console navigation menu, click Cloud Build > Triggers.
Select your project and click Open.
In the hello-world-trigger row, click the
Select Delete.
You have now deleted the trigger associated with your cloned repository.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2026-06-09 UTC.