Skip to content
Back to Cloud Services

GCP Cloud Build CI/CD

Managed CI/CD — Docker builds, multi-step pipelines, triggers on Git push, and artifact publishing.

GCPIntermediate

Why

Cloud Build runs Docker natively (Kaniko cache), 120 build-min/day free. Triggers on GitHub/Cloud Source Repos push.

Integrates with Artifact Registry, GKE, Cloud Run deploys.

When

Use for GCP-native CI/CD. Use GitHub Actions for multi-cloud, Cloud Deploy for progressive delivery.

How

1. cloudbuild.yaml — steps, images, timeout 2. Steps — Docker build, push, deploy, run tests 3. Triggers — on push to branch, PR, or manual 4. Substitutions — variables like $SHORT_SHA, $BRANCH_NAME 5. Cache — Kaniko cache for Docker layers, speeds builds 6. Parallel — steps run in parallel if no deps 7. Cloud Deploy — progressive delivery to dev → staging → prod 8. Secrets — Secret Manager, mount in build

Example

# cloudbuild.yaml steps: - name: gcr.io/cloud-builders/docker args: [build, -t, gcr.io/$PROJECT_ID/app:$SHORT_SHA, .] id: build - name: gcr.io/cloud-builders/docker args: [push, gcr.io/$PROJECT_ID/app:$SHORT_SHA] waitFor: [build] - name: gcr.io/google.com/cloudsdktool/cloud-sdk args: [run, deploy, app, --image, gcr.io/$PROJECT_ID/app:$SHORT_SHA, --region, us-central1] waitFor: [push] images: [gcr.io/$PROJECT_ID/app:$SHORT_SHA] # Trigger on push to main gcloud builds triggers create github \ --repo-name my-repo --repo-owner me \ --branch-pattern main \ --build-config cloudbuild.yaml

Common Problems

  • ⚠Build timeout 60min default — increase for long builds, max 24h
  • ⚠No cache by default — use Kaniko cache or --cache-from
  • ⚠Secrets in build — use Secret Manager, not env vars in cloudbuild.yaml

Best Practices

  • ✓Use Kaniko cache — Docker layer cache, 5x faster rebuilds
  • ✓Use Cloud Deploy for prod — progressive delivery, approvals, rollback
  • ✓Parallelize independent steps — waitFor controls, cuts build time

FAQ

What is GCP Cloud Build CI/CD and what problem does it solve?

Managed CI/CD — Docker builds, multi-step pipelines, triggers on Git push, and artifact publishing. It lets developers deploy, store, and scale without self-managing infrastructure — a core reference for cloud service selection.

How do I get started with GCP Cloud Build CI/CD in 5 minutes?

Two steps to run it: (1) cloudbuild.yaml — steps, images, timeout; (2) Steps — Docker build, push, deploy, run tests. Validate on the free tier first, then wire into production.

What is the #1 pitfall with GCP Cloud Build CI/CD?

The most frequent issue is: Build timeout 60min default — increase for long builds, max 24h. Run a pre-launch checklist item by item, and add policy/config scanning in CI.

What are the best practices for GCP Cloud Build CI/CD?

Best practices for GCP Cloud Build CI/CD include: Use Kaniko cache — Docker layer cache, 5x faster rebuilds; Use Cloud Deploy for prod — progressive delivery, approvals, rollback; Parallelize independent steps — waitFor controls, cuts build time. The first one — "Use Kaniko cache — Docker layer cache, 5x faster rebuilds" — should be a team default baked into your IaC templates.

How do I control cost and avoid bill surprises with GCP Cloud Build CI/CD?

Three ways to prevent overspend: (1) tag every resource with env/team and enable billing alarms; (2) set budget thresholds to trigger Slack/email alerts; (3) review idle resources in Cost Explorer regularly and clean them up. Most GCP Cloud Build CI/CD options offer a free tier — validate within free quota before scaling.