GCP DevOps Project

Sprint 04

Connecting Github repo to cloudbuild

Automate your CI/CD pipeline by linking GitHub with Google Cloud Build. Whenever you push code, Cloud Build can kick off your build and deployment processes without manual intervention.

Warning

Make sure billing is enabled on your Google Cloud project. Builds will fail if billing isn’t set up.

Prerequisites

RequirementDetails
Google Cloud ProjectActive project with billing enabled
IAM Roleroles/editor or roles/cloudbuild.builds.editor
GitHub AccountOwner or admin access to the target repository

1. Verify Your GCP Project

  1. Sign in to the Google Cloud Console.
  2. Confirm you’re working in the correct project.

The image shows a Google Cloud Platform (GCP) console dashboard for a project named "KodeKloud-GCP-Training," featuring options for creating virtual machines, running queries, and accessing various services.


2. Enable the Cloud Build API

  1. In the top search bar, type Cloud Build and select it.
  2. If you haven’t used Cloud Build here before, click Enable.
  3. Wait a minute for the API to be provisioned, then navigate back to Cloud Build.

3. Explore the Cloud Build Dashboard

  1. From the left-hand menu, choose Dashboard.
  2. You’ll see that no builds have run yet.
  3. Optionally, set your build region; otherwise leave the default global.

The image shows a Google Cloud Build interface with no build results displayed. It includes options to run a sample build or create a trigger.


4. Create a Build Trigger

Cloud Build triggers start builds automatically on repository events.

  1. In the left navigation pane, click Triggers.
  2. Select Manage repositories to view connected source repositories (initially empty).

The image shows a Google Cloud Build interface with a "Triggers" section open, indicating no triggers are found and options to create a trigger or connect a repository.


5. Connect Your GitHub Repository

  1. On Manage repositories, click Connect repository.
  2. Choose GitHub and press Continue—you’ll be redirected to GitHub for authentication.

The image shows a Google Cloud Build interface for managing repositories, with a sidebar for navigation and a panel for connecting a repository, including options for selecting a source like GitHub or Bitbucket.

  1. On GitHub:
    • Install the Google Cloud Build app.
    • Select Only select repositories and pick your repo (e.g., GCP DevOps project).
    • Click Install and authorize.

The image shows a Google Cloud Build interface for managing repositories, with a sidebar for navigation and a panel for connecting a GitHub repository. The panel includes options to select a source, authenticate, and select a repository, with a prompt to install Google Cloud Build on GitHub.

  1. Return to the Cloud Console:
    • Verify your GitHub account and repository selection.
    • Accept terms and click Connect.
    • Optionally, skip trigger creation by clicking Done for now.

The image shows a GitHub page for installing Google Cloud Build, with options to select repository access and permissions. A dropdown menu is visible on the right, showing account options for the user.

The image shows a Google Cloud Build interface where a repository connection process is being completed, with options to create triggers for automated builds. The right panel confirms a repository connection and provides trigger configuration options.


6. Verify the Connection

Back on Manage repositories, your GitHub repo should now appear. This confirms Cloud Build is linked and ready for triggers.


Next, you’ll create a cloudbuild.yaml file to define your build steps—compiling code, running tests, and pushing Docker images automatically.

Further Reading

Watch Video

Watch video content

Previous
Cloud Build trigger