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

Before you begin
- Sign in to your Google Cloud account. If you’re new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
- In the Google Cloud Console, on the project selector page, select or create a Google Cloud project.
- Make sure that billing is enabled for your Cloud project.
- Enable the Cloud Build API.
- If you don’t have one already, create an account on GitHub.
Prepare source files
You’ll need some sample source code to build. In this section, you’ll clone an existing source repository containing a Hello World example in Go to your own GitHub user account.
- Go to the Cloud Build cloud-build-samples repository.
- Fork the
cloud-build-samples
repository to your own GitHub account.
- 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.
- Click on Sign In. You will see
cloud-build-samples
repository present there.
- Clone the repository to your local machine by running the following command in your terminal, where GITHUB_USERNAME is the username for your GitHub account:
git clone https://github.com/GITHUB_USERNAME/cloud-build-samples.git
In our case it is:
git clone https://github.com/rajeevkghosh/cloud-build-samples.git
- Navigate to the
quickstart-automate
directory:
cd cloud-build-samples/quickstart-automate
- You will see the following files containing source code for your Hello World example:
main.go
: a sample Go application that printsHello, world!
package main
import (
"fmt"
)
func main() {
fmt.Println("Hello, world!")
}
cloudbuild.yaml
: the build configuration file used by Cloud Build to perform actions specified as build steps. The build step used in this file instructs Cloud Build to use thegolang
image from Docker Hub to build and run themain.go
file.
steps:
- name: golang
args: ['go', 'run', 'quickstart-automate/main.go']
Connect your repository
To build source code on GitHub using triggers, you must first connect Cloud Build to your GitHub repository. In this section, you’ll connect your cloud-build-samples
repository to Cloud Build.
- Open the Triggers page in the Google Cloud Console:Open Triggers page
- Select your project and click Open.
- Click Connect repository.
- Under Select source, select GitHub (Cloud Build GitHub App).
- Click Continue.
- Authenticate your GitHub account.
Click on “Authorize Google Cloud Build”.
- In the Select repostory section, enter your GitHub account username by clicking Add.You will see a pop-up to install the Cloud Build GitHub app.
- Click on “Install Google Cloud Build” and 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 Repository, select GITHUB_USERNAME/cloud-build-samples as your repository.
- Click the checkmark to agree to terms and conditions for trigger connection.
- Click Connect
- Click Done.You will create a trigger in the next section.
Create a trigger
In this section, you will create a trigger.
- Open the Triggers page in the Google Cloud Console:Open Triggers page
- Select your project from the project selector drop-down menu at the top of the page.
- Click Open.
- Click Create trigger.On the Create trigger page, enter the following settings:
- Name: Enter
hello-world-trigger
as the name of your trigger. - Event: Select Push to a branch as the repository event to invoke your trigger.
- Source: Select the
cloud-build-samples
repository as your source, which contains your source code and your build config file. - Build Configuration: Choose Cloud Build configuration file as your build config file.
- Cloud Build configuration file location: Specify the path to your Cloud Build configuration file as
quickstart-automate/cloudbuild.yaml
.
- Name: Enter


- Click Create to save your build trigger.

Create new Personal Access Token for Github
From August 13, 2021, Github is no longer accepting account passwords when authenticating Git operations. So here all you need to do is just create a new personal access token and use it instead of a Password. Here is How You can generate PAT
Step 1: First of all Open your GitHub account in your browser.
Step 2: Then In the upper-right corner of any page, click your profile photo, then click Settings.
Step 3: Now In the left sidebar, click Developer settings.
Step 4: In the left sidebar there are option of Personal access tokens. click Personal access tokens.
Step 5: Click on generate new Token
Step 6: Give name to your token and check mark permission you want give access.
Step 7: Click on Generate token.
Step 8: Click to copy the token to your clipboard. And Just Remember For security reasons, after you navigate off the page, you will not be able to see the token again. So Don’t Forgot to copy your new token.
Step 9: Update remote URL
git remote set-url origin https://<tour_new_token>@github.com/<git_url>
git remote set-url origin https://ghp_quJ7Uwnq5SzXXXXXXXXXH5hqx@github.com/rajeevkghosh/cloud-build-samples

Step 10 pull once: git pull https://<token>@<git_url>.git

Thats It. Now you can pull your code Or Push your code
Commit a change
In this section, you will commit a change to your cloned cloud-build-samples
repository on your own GitHub account.
- In the terminal window, navigate to the
quickstart-automate
directory:
cd cloud-build-samples/quickstart-automate

Before the update, the main.go file:

- Open the
main.go
file in Vi Editor. - Update the line containing “Hello, world!” to “Hello, universe!”
package main
import (
"fmt"
)
func main() {
fmt.Println("Hello, Universe!!!")
}

- Navigate back to the root directory of your repository:
cd ..
- Commit your changes to GitHub by running the following command:
git add quickstart-automate/main.go
git commit -m "update text"
git push

- You have now pushed a change to your repository. Your push will result in an automatic build by your trigger.
View build details
In this section, you will view the build details associated with your invoked build after committing a change.
- Open the Cloud Build page in the Google Cloud Console.Open the Cloud Build page
- Select your project and click Open.You will see the Build history page:

- Click on a particular build.You will see the Build details page.
- To view the artifacts of your build, under Build Summary, click Build Artifacts.You will see an output similar to the following:

- You can download your build log from this page.

Clean up
To avoid incurring charges to your Google Cloud account for the resources used in this quickstart, follow these steps.
- Open the Triggers page in the Google Cloud Console.Open the Build triggers page
- Select your project from the project selector drop-down menu at the top of the page.
- Click Open.
- Locate the row with the trigger you would like to delete.
- Click on the menu (vertical ellipses) located at the right end of the row.
- Select Delete.
You have now deleted the trigger associated with your cloned repository.
The point of view of your article has taught me a lot, and I already know how to improve the paper on gate.oi, thank you. https://www.gate.io/ja/signup/XwNAU
I am a website designer. Recently, I am designing a website template about gate.io. The boss’s requirements are very strange, which makes me very difficult. I have consulted many websites, and later I discovered your blog, which is the style I hope to need. thank you very much. Would you allow me to use your blog style as a reference? thank you!
Thanks for sharing. I read many of your blog posts, cool, your blog is very good. https://www.binance.com/sv/register?ref=V2H9AFPY