blue and red cargo ship on sea during daytime

Build Docker Images using Google Cloud Build from Your GitHub Repository

Triggering a Docker image build on Google Cloud Build when pushing commits to a GitHub repository.

Create Google Cloud Build Configuration File

Create a cloudbuild.yaml in the root folder:

- id: my-blog-cache-image
  entrypoint: "/bin/bash"
   - "-c"
   - |
     docker pull$PROJECT_ID/my-blog:$BRANCH_NAME || exit 0
  waitFor: ["-"]
- id: my-blog-build-image
  args: [
    "-t", "$PROJECT_ID/my-blog:$BRANCH_NAME",
    "-t", "$PROJECT_ID/my-blog:$SHORT_SHA",
  waitFor: ["my-blog-cache-image"]

If you want to push images to another region, simply rename to something like


Configure Google Cloud Build with Your GitHub Repository

Go to Google Cloud Dashboard > Google Cloud Build > Triggers > Create trigger

  • Region: Global
  • Event: Push to a branch
  • Source: 1st Gen
  • Repository:
    • Connect new repository
    • Source code management provider: GitHub (Cloud Build GitHub App)
    • Install Google Cloud Build GitHub app
    • Only select repositories
  • Branch: ^main$
  • Type: Autodetected
  • Location: Repository

That's it, now you could push some commits to your GitHub repository.