You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
Google Cloud Build is a fully managed continuous integration and continuous delivery (CI/CD) platform that lets you build, test, and deploy software on Google Cloud. It executes your builds as a series of steps in Docker containers, giving you full control over the build environment while eliminating the need to manage build servers.
Cloud Build is a serverless CI/CD service. You define build steps in a configuration file, and Cloud Build executes them in isolated containers. Each step runs in its own container, and steps can share data through a persistent workspace volume.
| Characteristic | Description |
|---|---|
| Serverless | No build servers to provision or manage |
| Container-based | Each build step runs in a Docker container |
| Fast | Parallel step execution and build caching |
| Secure | Runs in isolated environments with IAM-based access |
| Flexible | Any Docker image can be a build step |
| Integrated | Native integration with GCP services |
| Free tier | 120 build-minutes per day for the first region |
Cloud Build uses a cloudbuild.yaml (or cloudbuild.json) file to define the build pipeline:
steps:
# Step 1: Install dependencies
- name: 'node:18'
entrypoint: 'npm'
args: ['install']
# Step 2: Run tests
- name: 'node:18'
entrypoint: 'npm'
args: ['test']
# Step 3: Build the Docker image
- name: 'gcr.io/cloud-builders/docker'
args: ['build', '-t', 'gcr.io/my-project/my-app:latest', '.']
images:
- 'gcr.io/my-project/my-app:latest'
options:
machineType: 'E2_HIGHCPU_8'
logging: CLOUD_LOGGING_ONLY
Each step is a container execution:
| Field | Description |
|---|---|
| name | Docker image to use for this step |
| args | Arguments passed to the container entrypoint |
| entrypoint | Override the default entrypoint |
| dir | Working directory within the container |
| id | Unique identifier for the step (for dependencies) |
| waitFor | Steps that must complete before this step runs |
| env | Environment variables for the step |
| secretEnv | Secret Manager references for sensitive variables |
| timeout | Maximum duration for the step |
Cloud Build provides pre-built builder images for common tools:
| Builder | Image | Purpose |
|---|---|---|
| Docker | gcr.io/cloud-builders/docker | Build and push Docker images |
| gcloud | gcr.io/cloud-builders/gcloud | Run gcloud CLI commands |
| kubectl | gcr.io/cloud-builders/kubectl | Deploy to GKE |
| gsutil | gcr.io/cloud-builders/gsutil | Interact with Cloud Storage |
| git | gcr.io/cloud-builders/git | Git operations |
| npm | gcr.io/cloud-builders/npm | Node.js package management |
| go | gcr.io/cloud-builders/go | Build Go applications |
| maven | gcr.io/cloud-builders/mvn | Build Java/Maven projects |
You can also use any public Docker image or your own custom builder images.
# Run a build from the current directory
gcloud builds submit --config=cloudbuild.yaml .
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.