Cloud Build in Google Cloud
A complete, friendly guide to the serverless service that builds, tests, and delivers your software automatically: how it works inside, how to write build recipes, how to make builds fast and safe, and how to connect it to the rest of Google Cloud.
Every piece of software begins as plain text written by people. Before anyone can use it, that text has to be turned into something that actually runs: it must be gathered together, checked for mistakes, packaged neatly, and placed where users can reach it. Doing all of that by hand, again and again, is slow, boring, and easy to get wrong. One forgotten step on a tired Friday evening can break a website for thousands of people.
Cloud Build is the Google Cloud service that does this repetitive work for you, automatically and the same way every time. You write down a recipe once. From then on, whenever someone changes the code, Cloud Build follows the recipe on a fresh, clean computer in Google’s data centers, and reports back whether everything worked.
In this guide you will start from the very basics of what it means to build software, and then build up step by step to triggers, security, speed, cost, and real-world pipelines. Every new word is explained the first time it appears, with a comparison from everyday life.
1What Is Cloud Build?
Before any details, let us get one clear picture of what Cloud Build is, what it does, and why people use it.
Cloud Build is a serverless service on Google Cloud that runs your build, test, and delivery tasks. “Serverless” means you do not rent, set up, or look after any computers yourself. You hand Cloud Build a list of tasks, Google finds a machine, runs the tasks, and then throws the machine away. You pay only for the time used.
The tasks are described in a build configuration, a small text file that lists the steps to perform in order. Typical steps are: fetch the code, run automated tests, package the program into a container image, save that image in a safe storage place, and finally deploy it so people can use it.
This whole idea is called CI/CD. The letters stand for continuous integration, which means automatically combining and checking everyone’s code changes very often, and continuous delivery (or deployment), which means automatically getting the checked code to a place where it can run. Cloud Build is Google Cloud’s engine for CI/CD.
Think of a bakery with a very reliable robot baker. You give the robot a recipe card: mix these ingredients, bake for this long, check the loaf, wrap it, and place it on the shelf. Every time you change the recipe or bring new ingredients, the robot does the whole job again, in a spotless kitchen, exactly as written. Cloud Build is that robot, the recipe card is the build configuration, and the loaf is your finished software.
What people use it for
Packaging applications
Turn source code into container images or other packages that are ready to run.
Automatic checks
Run unit tests, style checks, and security scans every time code changes.
Deploying to Google Cloud
Push new versions to Cloud Run, Google Kubernetes Engine, App Engine, and more.
Applying cloud setup
Run tools that create or update cloud resources from written descriptions.
Scheduled jobs
Run maintenance or data tasks in a clean environment, on a timer or on request.
Releasing packages
Create and publish libraries, documents, and mobile app files.
Cloud Build is not tied to one programming language. Because each step is just a container running a command, anything you can run in a container can be a step: Java, Python, Go, JavaScript, mobile builds, document tools, and more.
2CI/CD Basics: The Words You Need
A handful of everyday terms from software delivery make the rest of this guide easy to follow.
Source code
The human-written instructions of a program, stored as text files.
Repository
A folder with a full history of the code, kept by a version control tool such as Git. Often called a repo.
Commit
A saved snapshot of changes in a repository, with a message and an author.
Branch and tag
A branch is a separate line of work. A tag is a name stuck on one exact moment, such as a release version.
Pull request
A proposal to merge one branch into another, which teammates review before it is accepted.
Build
The act of turning source code into something runnable, including all checks along the way.
Artifact
Anything a build produces and keeps: an image, a package, a report, a downloadable file.
Pipeline
A series of automated stages, such as build, test, scan, and deploy, that code passes through.
Container
A lightweight, sealed box holding a program and everything it needs, so it behaves the same on any computer.
Image
The frozen template from which containers are started. Think of it as a sealed meal kit.
Registry
A library that stores container images so they can be fetched later. Google’s is called Artifact Registry.
Trigger
A rule that says “when this happens, start that build”, such as a new commit.
Why automate at all?
| By hand | With automation |
|---|---|
| Steps live in someone’s memory or an old document | Steps are written in a file that everyone can read and improve |
| Works on one developer’s laptop, fails elsewhere | Always runs in the same clean environment |
| Tests are skipped when people are in a hurry | Tests run every single time |
| Releases are rare and scary | Releases are frequent, small, and boring |
| Mistakes are found by customers | Mistakes are found minutes after the change |
| Hard to know who released what, and when | Every build leaves a record |
Imagine a school where every homework page is checked by the teacher once, at the end of the year. Mistakes pile up, and nobody remembers why. Continuous integration is like checking each page the same day it is written. Small mistakes are cheap to fix, and nothing builds up behind your back.
“Build” can mean more than compiling. For languages like Python or JavaScript there may be nothing to compile, yet there is still plenty to do: install dependencies, run tests, and package the result. Cloud Build handles all of these as ordinary steps.
3A Short History and Where Cloud Build Fits
Knowing how software delivery grew up explains why Cloud Build is designed the way it is.
The manual era
Developers copied files to servers by hand and followed long checklists. Releases happened a few times a year and often went wrong.
Scripts and build servers
Teams wrote scripts and ran them on shared build servers. Tools like Jenkins became popular. Someone had to keep those servers healthy, patched, and big enough.
The container revolution
Containers made it possible to package a program and its tools into a sealed box. Builds could run the same way everywhere.
Hosted CI services
Cloud providers began running build machines for you, billing by the minute. No more babysitting build servers.
Cloud Build
Google introduced Cloud Build as a managed, container-based builder. Each step is a container, and the machines are created on demand and thrown away after use.
Supply chain security
As attacks on software delivery grew, features such as build provenance records, private networking, and tighter identity controls became central to the service.
Where it sits in Google Cloud
Cloud Build is one piece of a larger delivery toolbox. It is the “make it” engine, and it works closely with its neighbors.
- Source code hosts such as GitHub, GitLab, Bitbucket, and Google’s own source hosting tell Cloud Build when code changes.
- Artifact Registry stores the images and packages that builds produce.
- Cloud Deploy manages release stages and promotions across environments such as test, staging, and production.
- Cloud Run, Google Kubernetes Engine, App Engine, and Cloud Functions are common places to run what is built.
- Secret Manager holds passwords and keys that builds need.
- Cloud Logging and Cloud Monitoring record what happened.
- Binary Authorization can block images that were not built and approved the right way.
- Pub/Sub carries build status messages to other systems.
Product names, features, and defaults on Google Cloud change over time. Use this guide to learn the ideas, and confirm the current details in the official documentation before you finalize a design.
4Core Concepts of Cloud Build
A small set of ideas explains almost everything Cloud Build does.
Build
One complete run of your recipe. It has a unique identifier, a status, a start time, a finish time, and logs.
Step
One action inside a build. Each step runs inside its own container and does one clear job.
Builder
The container image used by a step. It carries the tool needed, such as a Git client, a Docker client, or a language toolkit.
Build configuration
The text file that lists steps, settings, images to save, and options. Commonly written in YAML, a simple readable format, though JSON also works.
Workspace
A shared folder that every step in a build can read and write. It is how steps pass files to each other.
Trigger
A saved rule that starts builds automatically when something happens, or on request.
Substitution
A named placeholder in the recipe that is replaced by a real value when the build runs.
Images and artifacts
The things the build keeps after it ends, because everything else is deleted along with the machine.
Worker pool
The group of machines where builds run: Google’s default shared pool, or a private pool that you control.
Service account
The robot identity that the build uses when it calls other Google Cloud services. What it may do depends on the permissions you grant.
The one big idea: the machine is temporary
Each build starts on a fresh virtual machine and that machine disappears afterward. Nothing from the previous build is left behind unless you saved it somewhere permanent. This is a feature, not a flaw. It means builds are repeatable: the same input gives the same result, and leftovers from old builds cannot silently change today’s outcome.
It is like renting a fully equipped kitchen by the hour. You walk in, cook with the tools provided, put the finished food in your own lunchbox, and leave. The staff then clean the kitchen completely before the next person arrives. If you forget to pack the food, it is gone.
Beginners often forget that files created inside a build vanish when it ends. Always push finished images to a registry, or copy files to Cloud Storage, as a step in the recipe.
5Architecture and Components
Here is the bigger picture of how code travels from a developer’s keyboard to a running application.
flowchart LR
DEV["Developer pushes code"] --> REPO["Source repository"]
REPO --> TRG["Build trigger"]
TRG --> CB["Cloud Build service"]
CB --> POOL["Worker pool: fresh virtual machine"]
POOL --> S1["Step 1: fetch and prepare"]
S1 --> S2["Step 2: test"]
S2 --> S3["Step 3: build image"]
S3 --> AR["Artifact Registry"]
S3 --> DEP["Deploy to Cloud Run, GKE or others"]
CB --> LOG["Cloud Logging and build history"]
CB --> PUB["Pub/Sub status messages"]
The control side and the work side
It helps to picture Cloud Build in two halves. The control side is the managed service that accepts requests, checks permissions, queues builds, tracks status, and keeps history. The work side is the pool of virtual machines that actually run the steps. You never log in to either half. You only talk to the service through the console, the command-line tool, or the programming interface.
How the steps share a machine
All steps in one build run one after another on the same machine by default. Every step is its own container, but they all see the same shared workspace folder. The first step might download code into that folder, the second might run tests on it, and the third might package it. When steps are marked as independent, they can run side by side to save time.
| Component | Role | Who manages it |
|---|---|---|
| Cloud Build service | Accepts builds, schedules them, records status | |
| Default worker pool | Shared machines that run builds | |
| Private worker pool | Machines dedicated to your project, reachable from your private network | Google runs them, you configure them |
| Triggers | Rules that start builds | You |
| Build configuration | The recipe | You |
| Builders | Tool containers used by steps | Google, the community, or you |
| Artifact Registry and Cloud Storage | Long-term storage for results | You |
| Service account | Identity and permissions of the build | You |
Picture a restaurant. The front desk (the control side) takes orders, writes tickets, and tracks which table is waiting. The kitchen (the work side) cooks each dish in a clean station. Customers never walk into the kitchen. They place an order and receive a dish.
Global and regional builds
A build can run in a chosen region or be handled by the service globally. A regional build keeps the processing and the logs in the place you pick, which helps when company or legal rules say where data must stay, and it keeps delays low when the registry and deployment targets are nearby. A global build is simpler to set up, because you do not have to decide on a place. When you have no strict rule, choose the region nearest to your artifacts and keep everything consistent, since mixing many regions makes pipelines harder to understand and can add data transfer charges.
The role of the command-line tool and the console
You can work with Cloud Build in three ways. The console is the web page where you create triggers, read logs, and look at history. The command-line tool lets you start builds from a terminal or from a script, which is useful for quick experiments and for other automation. The programming interface lets your own software start and watch builds. All three talk to the same service, so a build started in one way appears in the history of the others.
6Internal Working: The Life of One Build
Let us follow a single build from the moment it is requested to the moment its machine disappears.
sequenceDiagram
participant U as You or a Trigger
participant API as Cloud Build API
participant Q as Scheduler
participant W as Worker Machine
participant R as Registry or Storage
participant L as Logs
U->>API: Request a build with a recipe
API->>API: Check permissions and validate the recipe
API->>Q: Queue the build
Q->>W: Assign a fresh machine
W->>W: Download source into the workspace
W->>W: Run steps one by one in containers
W->>L: Stream log lines
W->>R: Push images and artifacts
W-->>API: Report final status
API-->>U: Success, failure or timeout
The stages in plain words
Request
A person, a script, or a trigger asks for a build. The request carries the recipe and a pointer to the source code, or the code itself.
Validation
The service checks that the caller has permission and that the recipe is well formed. Typos are caught here, before any machine is used.
Queueing
The build waits for a free slot. If many builds are already running, yours stays queued until capacity is available.
Machine assignment
A fresh virtual machine is prepared. This includes fetching the builder images that your steps will use.
Source preparation
Your source code is placed into the shared workspace folder.
Step execution
Each step starts its container, runs its command, and ends. A step that finishes with an error code stops the whole build, unless the recipe says otherwise.
Saving results
Images listed in the recipe are pushed to the registry. Artifacts are copied to Cloud Storage.
Completion
The final status is recorded: success, failure, timeout, or cancelled. Logs are kept, notifications are sent, and the machine is destroyed.
Statuses you will see
| Status | Meaning |
|---|---|
| Queued | Waiting for a machine |
| Working | Steps are running |
| Success | All steps passed and results were saved |
| Failure | A step failed |
| Internal error | A problem on the service side, usually worth retrying |
| Timeout | The build ran longer than its allowed time |
| Cancelled | Someone stopped it |
A build is like a relay race held on a brand-new track. Each runner (step) must finish before passing the baton (the workspace folder) to the next. If anyone drops the baton, the race stops and the officials record it. After the race, the track is cleared.
Every build has a time limit, with a default measured in minutes and a much larger maximum. Set a sensible timeout of your own, so that a stuck step fails quickly instead of quietly using up time and money.
7The Build Configuration File
The build configuration is the recipe card. Understanding its parts lets you read any Cloud Build pipeline.
The file is usually named cloudbuild.yaml and kept in the same repository as the code, so the recipe is versioned together with the program. That is a powerful habit: when you go back to an old version of the code, you also get the old recipe that built it.
The main sections
| Section | What it holds | Why it matters |
|---|---|---|
| steps | The ordered list of actions | The heart of the recipe |
| images | Names of container images to push to a registry when all steps succeed | Ensures the final image is saved |
| artifacts | Files or packages to copy out of the workspace to storage | Keeps test reports, packages, and other outputs |
| substitutions | Named placeholders with default values | Makes one recipe reusable |
| timeout | Maximum time for the whole build | Stops runaway builds |
| options | Machine type, disk size, logging mode, pool choice, and more | Controls speed, cost, and behavior |
| available secrets | Pointers to values stored in Secret Manager | Lets steps use secrets safely |
| service account | The identity the build runs as | Controls what the build is allowed to touch |
| tags | Labels attached to the build | Helps search and organize history |
| queue time-to-live | How long a build may wait before being dropped | Avoids stale builds running late |
What one step can say
name
The builder image to use for the step.
args and entrypoint
The command and arguments to run. The entrypoint overrides the builder’s default program.
id
A short name for the step, so other steps can refer to it.
wait for
A list of step ids that must finish first. This lets independent steps run in parallel.
dir
Which folder inside the workspace to run in.
env
Environment variables, which are small named settings visible to the program.
secret env
Which secrets from Secret Manager this step may read.
timeout
A time limit for this one step.
allow failure
Lets the build continue even if this step fails, for non-critical checks.
Reading a recipe in your head
A simple recipe for a web application might say, in words: first, run the test tool in a language container; second, build a container image from the project’s instructions file; third, push the image to Artifact Registry; fourth, tell Cloud Run to use the new image. The “images” section lists the image name so that Cloud Build also records it as an official output of the build.
The file is like a flat-pack furniture manual. It lists which tools to use at each stage, in which order, what to do if a part is missing, and which finished pieces go into the box at the end. Anyone who follows it gets the same wardrobe.
Use clear step ids such as “unit-tests”, “build-image”, and “deploy”. They make the logs easy to read and make parallel-step design much simpler.
8Builders: The Tools Inside Each Step
Because every step is a container, a builder is simply a container that happens to hold a useful tool.
Cloud builders
A set of ready-made images maintained by Google, covering common tools such as Git, the Docker client, the Google Cloud command-line tool, and kubectl for Kubernetes.
Community builders
Images shared by the open-source community for other tools. They are useful, but you should review their source before trusting them.
Public images
Any public container image can be a builder, such as official language images from Docker Hub.
Custom builders
Images you build yourself with the exact tools and versions your team needs, stored in your own registry.
Ways to build container images
| Approach | How it works | Good for |
|---|---|---|
| Docker build step | Uses the instructions file in your repository to assemble an image | The most common and flexible approach |
| Buildpacks | Detect the language of your project and assemble a secure image without you writing image instructions | Teams who want less container work |
| Kaniko-style builders | Build images without needing a privileged Docker service and support layer caching in a registry | Faster repeat builds with simple caching |
| Language-specific tools | Tools for particular ecosystems that create images straight from the project | Java and similar stacks |
Choosing builders wisely
- Pin versions. Use a specific version tag, or better a digest, for each builder so that a surprise update does not change your build overnight.
- Prefer small images. Smaller builders download faster, saving seconds on every step of every build.
- Trust carefully. A builder runs with the build’s permissions. A malicious builder could read secrets or tamper with output. Prefer images from sources you trust and consider keeping approved copies in your own registry.
- Keep one tool per step. A step that does one clear thing is easier to debug and cache.
Builders are the toolboxes a carpenter picks up for each job. One toolbox for measuring, one for cutting, one for painting. You can borrow standard toolboxes from the hardware store, or fill your own with exactly what you like. But you would not accept a toolbox from a stranger without looking inside.
Using a “latest” tag for builders makes builds unrepeatable. A build that passed yesterday may fail today only because a tool changed. Pin versions on purpose.
9Triggers and Source Repositories
Triggers are what turn Cloud Build from a tool you run into a system that runs by itself.
A trigger says: “When this event occurs in this repository, start a build with this recipe.” You can create as many triggers as you like, each with its own rules and recipe.
Kinds of events
Push to a branch
A new commit lands on a branch whose name matches a pattern, such as the main branch.
Push of a tag
A release tag is created, a natural moment to build and publish a version.
Pull request
A proposed change is opened or updated, so checks run before merging.
Run on request
A person presses a button or calls the programming interface. Optionally an approval can be required first.
Pub/Sub event
A message arrives on a topic, for instance when an image changes or a schedule fires.
Webhook
Another system calls a special web address to start the build.
flowchart TD
E["Something happens in the repository"] --> M{"Does it match a trigger?"}
M -->|"No"| N["Nothing starts"]
M -->|"Yes"| F{"Do changed files match the include and ignore filters?"}
F -->|"No"| N
F -->|"Yes"| A{"Is approval required?"}
A -->|"Yes"| P["Wait for a person to approve"]
A -->|"No"| B["Start the build"]
P -->|"Approved"| B
P -->|"Rejected"| N
Useful trigger settings
- Branch and tag patterns: Match names such as “main” or anything beginning with “release”. These patterns are called regular expressions.
- Included and ignored files: Start a build only if certain folders changed, or skip it when only documents changed. This is vital in repositories that hold many projects.
- Substitutions: Give each trigger its own values, so one recipe can serve test and production.
- Service account: Choose which identity the triggered build uses.
- Approval: Ask a person to approve before important builds, such as production releases.
- Comment control: For pull requests from outside contributors, require a trusted reviewer to approve the build first, so a stranger cannot run code with your build’s permissions.
Connecting source code
Cloud Build can connect to repositories on popular hosts such as GitHub, GitLab, and Bitbucket, as well as Google’s own hosting option. The connection is made once, with an app or token that you authorize, and after that triggers can watch the repositories you choose. The exact connection methods have changed over the years, and newer connection styles exist alongside older ones, so follow the current documentation when you set this up.
A trigger is a motion sensor on a porch light. It stays quiet most of the time and switches on only when the right thing happens. Filters are like telling the sensor to ignore cats but react to people.
Building every pull request from anyone, with full permissions, is dangerous. Someone can change the recipe in their pull request to steal secrets. Use comment control, limit permissions, and keep deployment steps out of untrusted builds.
Manual, scheduled, and approved builds
Not every build is caused by code. Sometimes a person wants to press a button, for example to release a version at an agreed time. Sometimes a build should run every night, such as a full rebuild without any caches, a security scan of the latest dependencies, or a data task. For schedules, you pair a timer service with a trigger so that a message or a web call starts the build at the chosen moment. For sensitive builds, you can mark a trigger as needing approval: the build is created but waits, and only someone with the right permission can release it to run. This gives a simple human checkpoint before production changes, and the approver and time are recorded in the history.
A scheduled build is like an alarm clock that starts the coffee machine every morning. An approval-gated build is like a bank vault that opens only when a manager turns a second key.
10Substitutions, Variables, and Secrets
A good recipe is flexible and safe. Substitutions make it flexible, and secrets handling makes it safe.
Substitutions: fill-in-the-blank values
A substitution is a placeholder whose name begins with a dollar sign. When a build runs, Cloud Build replaces each placeholder with its real value. This lets a single recipe be used for different branches, projects, and environments.
| Kind | Examples of what it gives you | Who sets it |
|---|---|---|
| Default substitutions | The project identifier, the build identifier, the region | Cloud Build |
| Repository substitutions | The commit identifier, branch name, tag name, repository name, short commit identifier | Cloud Build, when started by a trigger |
| User-defined substitutions | Your own names, such as an environment name or a deployment region | You, in the recipe or the trigger |
Custom substitution names conventionally start with an underscore, which keeps them separate from the built-in ones. A very common habit is to tag each image with the short commit identifier, so you can always tell exactly which code produced a given image.
Secrets: keep passwords out of the recipe
A recipe is stored in a repository that many people can read. Never write passwords, keys, or tokens in it. Instead:
- Store the secret in Secret Manager, Google Cloud’s safe for sensitive values.
- In the recipe, list which secrets exist and give them short names.
- In only those steps that truly need a secret, expose it as an environment variable that exists just for that step.
- Give the build’s service account permission to read just those secrets.
Cloud Build also hides known secret values in its logs, but you should not rely on that alone. Never print a secret on purpose.
Substitutions are like a form letter with blanks for the name and date. Secrets are like the key to a safe: you do not write it on the letter. You tell the courier which safe to open, and the courier opens it only at the moment it is needed.
Prefer short-lived, narrowly scoped credentials. Instead of storing a long-lived deployment key, give the build’s service account just the roles needed, and let Google Cloud handle the identity behind the scenes.
11Artifacts, Registries, and Caching
Since build machines are thrown away, you must save the results deliberately, and you can also save time by remembering earlier work.
Where results go
Artifact Registry
The recommended home for container images, and also for language packages such as those for Java, Python, and JavaScript.
Cloud Storage
A general file store, good for test reports, binaries, website files, and any other output.
Cloud Logging and storage buckets
Where build logs are written, depending on your logging choice.
Build metadata
Information about which build made which image, kept for tracking and for provenance.
Images versus artifacts
The “images” section of the recipe is for container images, which are pushed to a registry only if the whole build succeeds. The “artifacts” section is for other files, which are copied to Cloud Storage. Using these sections, rather than a manual push inside a step, lets Cloud Build record the outputs as official results of the build, which is useful for tracking and for security records.
Tagging images sensibly
- Tag with the commit identifier, so every image traces back to one exact change.
- Add a human-friendly tag, such as a version number, for releases.
- Avoid depending on a moving tag like “latest” in production. Deploy by digest or by a fixed tag.
Caching: not repeating work
Because each build starts clean, it may re-download the same libraries and re-create the same image layers every time. Caching remembers earlier results to skip repeated work.
| Technique | How it helps |
|---|---|
| Image layer caching | Pull the previous image first and let the image builder reuse unchanged layers. Layers are the stacked pieces of an image |
| Registry-based cache | Builders such as Kaniko store layers in a registry and reuse them across builds |
| Dependency caching | Save downloaded libraries to Cloud Storage and restore them at the start of the next build |
| Smart image instructions | Order the image instructions so that rarely changed parts come first, keeping cached layers valid for longer |
| Small context | Ignore unneeded files when sending source, so less is uploaded and fewer changes break the cache |
Caching is like keeping a jar of pre-chopped onions in the fridge. If tonight’s recipe is the same as last night’s, you skip the chopping. But if the recipe changes at the very first ingredient, everything after it must be redone, which is why the order of your steps matters.
Caches can hide problems. A build that depends on stale cached files may pass today and fail on a clean machine tomorrow. Run a full, uncached build now and then, such as nightly, to keep yourself honest.
Keeping the registry tidy
Every build that makes an image adds one more item to the registry. After a year of frequent builds there may be tens of thousands. Most are never used again, yet they cost storage money and make it harder to find the right one. Set cleanup rules that keep recent images and all images currently deployed, and delete the rest after a sensible period. Make sure the rule never removes an image that production still runs, because a server that restarts needs to pull it again.
Digests: the exact fingerprint
A tag is a label that can be moved from one image to another. A digest is a long fingerprint calculated from the image contents, so it points to exactly one image forever. Deploying by digest guarantees you run precisely what was tested. Many teams use human-friendly tags for convenience and digests in the final deployment, giving them both readability and certainty.
12Making Builds Fast
A slow pipeline makes people wait, and waiting people stop trusting automation. Speed is worth real effort.
flowchart TD
START["Fetch source"] --> LINT["Style checks"]
START --> UNIT["Unit tests"]
START --> SCAN["Dependency scan"]
LINT --> IMG["Build image"]
UNIT --> IMG
SCAN --> IMG
IMG --> PUSH["Push to registry"]
PUSH --> DEPLOY["Deploy"]
Main speed levers
Run independent steps together
Give steps ids and tell each one which earlier steps it must wait for. Steps that do not depend on each other will start at the same time.
Choose a bigger machine
Larger machine types have more processor cores and memory. Heavy compiles and tests can finish much sooner, though the price per minute is higher.
Use caching
Reuse image layers and downloaded libraries instead of fetching them again.
Smaller builders and images
Fewer bytes to download means less waiting at the start of every step.
Build only what changed
Use file filters so that unrelated changes do not start builds at all.
Keep things close
Use regions near your registry and your source. Distance adds delay for every download and upload.
The trade-off: time versus money
Builds are billed by the minute for the machine type used, so a bigger machine costs more per minute. But if it finishes in a quarter of the time, the total can be similar or lower, and developers get answers sooner. The way to find out is to measure: try the same build on two sizes and compare time and cost. Remember that some steps cannot use many cores, so a bigger machine is not always faster.
Measure first
- Look at the build timeline in the console to see which step takes longest.
- Attack the longest step first. Improving a ten-second step does little for a ten-minute build.
- Record build duration over time, so you notice when a change quietly makes things slower.
Cooking a big dinner is faster when several people chop vegetables, boil rice, and set the table at the same time, instead of one person doing every job in a line. A larger kitchen with more burners helps too, but it costs more to run. And if the rice takes the longest, a faster knife for the vegetables will not shorten dinner.
Queue time is separate from run time. If builds spend a long time waiting before they start, the cause may be concurrency limits or a small private pool, not your recipe.
13Worker Pools: Default and Private
Where a build runs matters for speed, security, and what the build can reach.
flowchart TD
Q{"What does the build need?"} --> A{"Must it reach private systems, such as an internal database or a private network?"}
A -->|"No"| B{"Need fixed machine sizes or stronger isolation?"}
A -->|"Yes"| PRIV["Use a private pool connected to your network"]
B -->|"No"| DEF["Use the default pool"]
B -->|"Yes"| PRIV
DEF --> D1["Shared, managed by Google, quick to start"]
PRIV --> P1["Dedicated to your project, you choose machine type and network"]
The default pool
The default pool is a shared fleet of machines run by Google. It needs no setup, starts quickly, and offers a range of machine sizes. Builds in it reach the public internet and Google Cloud services, but they cannot directly reach resources inside your private network. For most small and medium projects, this is the right place to start.
Private pools
A private pool is a set of build machines dedicated to your project. You decide the region, machine type, and disk size. Most importantly, a private pool can be connected to your own virtual private cloud network, the private network you build inside Google Cloud, so builds can reach internal systems such as a private database, an internal package server, or a code host that is not on the public internet. You can also restrict outbound internet access from the pool.
| Question | Default pool | Private pool |
|---|---|---|
| Set-up effort | None | Create and configure the pool and network connection |
| Access to private networks | No direct access | Yes, through peering or a similar private connection |
| Machine choice | A set of standard sizes | Wider choice, including larger machines |
| Isolation | Shared infrastructure managed by Google | Dedicated to your project |
| Outbound internet control | Open | Can be limited or blocked |
| Billing | Per build minute by machine type, with a free allowance | Per minute for the pool machines in use, with different pricing |
| Best for | Most standard builds | Regulated, private, or heavy builds |
Choosing regions
Builds can be started globally or in a specific region. Regional builds help meet rules about where data may be processed, and can reduce delay when your code, registry, and deployment targets are in the same area. Match the build region to where you keep your artifacts.
The default pool is like a public workshop with shared benches: easy to use and always open, but you cannot bring in your private tools or lock the door. A private pool is like renting your own workshop inside your company building: you decide the equipment and who gets in, and it has a door straight into your office.
A private pool with strict outbound limits will fail to download public packages unless you provide a route, such as an internal mirror or a controlled gateway. Plan how builds will get their dependencies before you lock down the network.
14Delivery Pipelines: From Build to Running Application
Building an image is only half the story. The real goal is getting the new version safely in front of users.
sequenceDiagram
participant Dev as Developer
participant Repo as Repository
participant CB as Cloud Build
participant AR as Artifact Registry
participant CD as Cloud Deploy
participant Stage as Staging
participant Prod as Production
Dev->>Repo: Merge a change
Repo->>CB: Trigger fires
CB->>CB: Test and build image
CB->>AR: Push tagged image
CB->>CD: Create a release
CD->>Stage: Roll out to staging
Stage-->>CD: Checks pass
CD->>Prod: Promote after approval
Where builds can deploy
Cloud Run
Run containers without managing servers. A deploy step points the service to the new image, and Cloud Run handles rollout and scaling.
Google Kubernetes Engine
Update the desired state of a cluster, so it pulls and runs the new image. Often done through release tools.
App Engine and Cloud Functions
Deploy source or packages straight to managed application platforms.
Cloud Storage and CDN
Copy built static website files to a storage bucket that serves visitors.
Virtual machines
Update machine groups with new images or startup instructions.
Infrastructure tools
Run tools that create or change cloud resources from written descriptions, often with a human approval gate before applying.
Cloud Build or Cloud Deploy?
Cloud Build is excellent at running tasks, including a deploy command. Cloud Deploy is a separate service designed for the release process itself: moving the same artifact through a series of environments, with approvals, history, and rollback. Many teams use both: Cloud Build makes and tests the image, then hands a release to Cloud Deploy. Small projects can simply deploy straight from Cloud Build.
Release strategies
| Strategy | How it works | Benefit | Cost |
|---|---|---|---|
| Replace in place | The new version replaces the old one | Simple | Mistakes reach everyone quickly |
| Rolling | Instances are updated a few at a time | No full downtime | Two versions run together for a while |
| Blue-green | A complete new copy is started, then traffic is switched | Instant switch and easy rollback | Needs double capacity during the switch |
| Canary | A small share of users gets the new version first | Problems affect few people | More monitoring and moving parts |
Releasing software is like opening a new menu at a restaurant chain. You do not change every branch on the same morning. You try the new dish in one branch (staging), watch the feedback, then roll it out to more (production). Cloud Build cooks the dish, and Cloud Deploy is the regional manager who decides when each branch gets it.
Build once, deploy many times. The exact same image that passed tests in staging should be the one promoted to production. Rebuilding for each environment can produce subtle differences.
A typical deployment to Cloud Run, in words
Prepare permission
The build’s service account is allowed to deploy to the chosen Cloud Run service and to act as the identity the service runs under.
Create the image
Earlier steps test the code, build the image, and push it with the commit identifier as its tag.
Deploy a new revision
A deploy step tells Cloud Run to create a new revision that uses the new image. Cloud Run starts it alongside the old one.
Shift traffic
Traffic can move all at once, or gradually, for example ten percent first and the rest later.
Check health
A final step calls a health address or reads monitoring results. If it fails, the pipeline sends traffic back to the previous revision.
Because Cloud Run keeps earlier revisions, going back is usually just a change of where traffic points, which is why serverless platforms make rollbacks so pleasant.
15Security: Identity, Secrets, and the Software Supply Chain
A build system holds the keys to your production environment. If an attacker controls the build, they control what your users run.
That is why build security has become one of the hottest topics in software. The set of everything that touches your software on its way to users, from source code to dependencies to build tools to registries, is called the software supply chain. Securing it means making sure each link is trusted and tamper-evident.
Service accounts and least privilege
Every build runs as a service account. Give it only the roles it needs. A build that only pushes images should not be able to delete databases. Using a dedicated account per pipeline limits the damage of any single mistake.
User-specified service accounts
You can pick which account a build or trigger uses. Google has changed the default account arrangements in recent years, so check what your project uses and choose a dedicated, minimal account on purpose.
Secret Manager
Keep sensitive values in a proper safe, give access only to the steps and accounts that need it, and rotate them regularly.
Private pools and perimeters
Run builds inside your private network, restrict outbound traffic, and use service perimeters to reduce the risk of data leaving.
Build provenance
Cloud Build can produce signed records describing what was built, from which source, by which build, and when. These records follow supply chain frameworks such as SLSA, a set of levels describing how trustworthy a build process is.
Binary Authorization
A deployment-time check that only allows images with the right signatures or attestations, meaning approved proofs, to run in your clusters or services.
Vulnerability scanning
Registry and analysis tools can scan images for known weaknesses in the packages they contain, so you can block or fix risky images.
Audit logs
Record who started builds, changed triggers, or altered permissions.
A chain you can trust
Protect the source
Require reviews before code is merged, and protect the main branches.
Control the recipe
Keep the build configuration in the repository under the same review rules, and be careful that untrusted contributors cannot change what a privileged build does.
Trust the tools
Pin builders to exact versions and keep approved copies in your own registry.
Check the ingredients
Scan dependencies and images, and keep a list of what each image contains, which is often called a software bill of materials.
Sign the result
Produce provenance and attestations that prove the image came from your pipeline.
Verify before running
Let the runtime environment accept only images that carry valid proofs.
Think of food safety. A chain restaurant checks the farm, the delivery truck, the kitchen, and the sealed packaging, and stamps each batch with a date and origin. If anything goes wrong, they can trace it back, and they refuse deliveries without proper stamps. Supply chain security does the same for software.
The most common serious mistake is giving the build service account broad project-wide powers “to make it work”. If the build is ever tricked into running a malicious step, those powers belong to the attacker. Start narrow and add only what you can justify.
Roles in plain words
Permissions in Google Cloud are grouped into roles. A build usually needs a small, predictable set of them. Think of it as a list of doors the build is allowed to open.
| Build needs to… | Kind of permission required |
|---|---|
| Push images to the registry | Write access to the specific repository in Artifact Registry |
| Write logs | Permission to write to Cloud Logging, or to the chosen storage bucket |
| Read a secret | Access to the specific secret in Secret Manager, nothing more |
| Deploy to Cloud Run | Permission to deploy to the service, plus permission to use the service’s identity |
| Update a GKE cluster | Limited permission to the specific cluster or namespace |
| Copy files to a bucket | Write access to that one bucket |
Grant each permission on the smallest thing possible, such as one repository or one secret, instead of the whole project. Review these permissions regularly, since pipelines change and old permissions are rarely removed unless someone checks.
16Monitoring, Logging, and Notifications
A pipeline that fails silently is worse than no pipeline. Make results visible to the right people at the right time.
Logs
Every build streams its output line by line. You can read it in the console while the build runs and afterward. Depending on the logging option you choose, logs are written to Cloud Logging, to a Cloud Storage bucket, to both, or in some cases not at all. When a build uses a user-specified service account, you must choose a logging option explicitly. Logs are the first place to look when a step fails.
Build history
The console keeps a list of past builds with status, duration, trigger, commit, and the timeline of each step. This makes it simple to answer questions such as “what changed between the last good build and the first bad one?”
Notifications
Pub/Sub build events
Cloud Build publishes a message when a build changes state. Any system can listen and react.
Chat and email alerts
Small notifier programs can read those messages and post to chat tools or send email when builds fail.
Status on pull requests
The result of a build is shown right next to the pull request, so reviewers see pass or fail at a glance.
Monitoring alerts
Create alerts from log-based metrics, such as the number of failed builds in an hour.
What to measure
| Measure | Why it matters |
|---|---|
| Build duration | Slow builds slow every developer down |
| Queue time | Shows capacity or concurrency problems |
| Success rate | A falling rate points to flaky tests or fragile steps |
| Time to fix a broken build | Shows how quickly the team reacts |
| Cost per build and per month | Prevents surprises on the bill |
| Deployment frequency | A healthy sign of small, frequent releases |
| Change failure rate | Share of releases that cause problems |
The last two, together with lead time from commit to production and the time to recover from a failure, are often called the four key delivery measures, widely used by teams to judge how well their delivery works.
Logs are the black box recorder of an airplane, notifications are the cockpit alarms, and metrics are the instrument dials. You hope to rarely need the recorder, but when something goes wrong it explains everything, and the dials warn you before it does.
Alert on failed builds of main branches and production deployments immediately. Failures of ordinary feature branches can usually wait for the author to look. Too many alerts teach everyone to ignore alerts.
Reading a failed build
When a build fails, a calm routine saves a lot of time. First look at which step failed in the timeline, then open that step’s log and find the first error line. Next, ask what changed since the last successful build: the code, the recipe, a builder version, a secret, or a permission. Finally, try to reproduce the failure in the same builder image. Writing down the cause and the fix in a short team note turns each failure into shared knowledge.
17Understanding Cost and Quotas
Cloud Build bills for the time your builds use machines. A little understanding keeps the bill small and predictable.
How charges usually work
- Build minutes: You are charged for the minutes that builds run, at a rate that depends on the machine type. Bigger machines cost more per minute.
- Free allowance: There is typically a monthly allowance of free build minutes on a standard machine type. The size of that allowance and which machine types it applies to have changed in the past, so check the pricing page.
- Private pools: Priced differently from the default pool, usually based on the machines in use.
- Other services: Storage for images and artifacts, logs, network transfer, and the services you deploy to all have their own prices.
Ways to keep costs down
Filter triggers
Skip builds for changes that do not matter, such as documentation edits.
Cache and parallelize
Less time per build means a smaller bill.
Match machine to job
Do not use a big machine for a tiny script. Do not use a tiny machine for a huge compile.
Set timeouts
A stuck build is stopped instead of running for hours.
Clean old images
Set cleanup rules in the registry so that thousands of old images do not pile up.
Budgets and alerts
Set budget alerts on the project to catch loops and mistakes early.
Quotas and limits
Cloud Build has limits, such as how many builds may run at the same time in a region, how many triggers you may create, and how large the source or logs may be. Extra builds wait in a queue. Limits and defaults change, so look at the quotas page in the console, set alerts as you approach them, and request increases before big launches.
Build minutes are like electricity on a meter. Leaving the lights on when nobody is in the room, running the heater on full for a tiny room, and ignoring a leaking tap all add to the bill. Good habits matter more than a clever tariff.
A trigger that listens to changes made by the build itself can create an endless loop. For example, a build that commits a version file back to the repository, which starts another build. Use file filters or skip markers to break such loops.
18Advantages, Disadvantages, Trade-offs, and Alternatives
No tool is right for everyone. An honest comparison helps you decide when Cloud Build fits.
Advantages
- Serverless: no build servers to set up, patch, or scale.
- Fresh, clean environment for every build, which makes results repeatable.
- Runs many builds in parallel.
- Pay for what you use, with a free allowance for small projects.
- Flexible: any tool that runs in a container can be a step.
- Deep integration with Artifact Registry, Cloud Run, GKE, Secret Manager, and logging.
- Private pools for builds that must reach internal networks.
- Supply chain features such as provenance and Binary Authorization.
Disadvantages
- Best suited to Google Cloud. Using it with other clouds works but is less natural.
- Starts clean every time, so caching needs deliberate design.
- Fewer ready-made pipeline “marketplace” components than some competitors.
- Complex workflows with many conditions can become long and hard to read.
- Concurrency limits and queueing can slow very busy teams unless they use private pools or request increases.
- Source connections and defaults have evolved, which can confuse people following older guides.
Key trade-offs
| Choice | One side | Other side |
|---|---|---|
| Convenience versus control | Default pool is zero-effort | Private pools give network control but need set-up |
| Speed versus cost | Large machines finish sooner | Smaller machines cost less per minute |
| Clean builds versus fast builds | Clean builds are fully repeatable | Caching saves time but can hide problems |
| Simple recipe versus flexibility | Short recipes are easy to understand | Many conditions handle more cases but are harder to maintain |
| Managed versus self-run | No operations work | Self-run tools allow deeper customization |
Alternatives to consider
- GitHub Actions is built into GitHub, with a huge library of shared actions. It is a natural choice for projects that live on GitHub, and it can still deploy to Google Cloud.
- GitLab CI is built into GitLab and covers the whole development lifecycle there.
- Jenkins is a long-established, self-hosted automation server with endless plugins, at the price of running and maintaining it.
- CircleCI and similar hosted services provide polished hosted pipelines across many platforms.
- AWS CodeBuild and Azure Pipelines are the equivalents on other major clouds.
- Tekton and Argo Workflows are open-source, Kubernetes-based pipeline engines for teams who want to run pipelines inside their own clusters.
Many organizations mix tools. A common pattern is to use the code host’s pipelines for tests and Cloud Build for the Google Cloud specific steps of building and deploying.
Choosing a CI/CD tool is like choosing how to get meals. Cloud Build is a good meal-delivery service when you live in Google’s neighborhood: convenient and tidy. Jenkins is owning a restaurant kitchen: total control, constant upkeep. Other hosted services are different delivery apps: each with its own menu, and the best one often depends on where you live.
19Design Patterns and Anti-patterns
Teams who run pipelines for years end up repeating the same good ideas, and avoiding the same bad ones.
Patterns that work
Pipeline as code
Keep the recipe in the repository, reviewed like any other code.
Build once, promote
Create one image and move that same image through every environment.
Fail fast
Run the quickest checks first, such as style and unit tests, so bad changes are rejected within a minute or two.
Parallel checks
Run independent checks side by side and join them before the build step.
Pinned, private builders
Use fixed versions of tools, kept in your own registry.
Separate accounts per pipeline
Each pipeline has its own minimal service account.
Approval gates
Production deployments wait for a human approval or an automatic policy check.
Immutable tags
Tag images with commit identifiers and never overwrite a released tag.
Shared recipe fragments
Reuse custom builders and common steps across many projects to keep them consistent.
Anti-patterns to avoid
| Anti-pattern | Why it hurts | Better approach |
|---|---|---|
| Secrets written into the recipe | Anyone with repository access can read them | Use Secret Manager and per-step access |
| Using the latest tag for builders or base images | Builds change without warning | Pin exact versions or digests |
| One giant account with owner rights | One mistake can wreck the project | Narrow roles per pipeline |
| Rebuilding for each environment | Production may differ from what was tested | Build once and promote the same image |
| Running every check serially | Long waits for no reason | Parallelize independent steps |
| Skipping tests to go faster | Defects reach users | Speed up tests, never remove them |
| Ignoring flaky tests | People stop trusting failures | Fix or quarantine flaky tests quickly |
| Manual changes to production | Nobody knows the true state | All changes flow through the pipeline |
| Building untrusted pull requests with full power | Attackers can steal secrets | Comment control and minimal permissions |
| Never cleaning registries | Cost and clutter grow forever | Retention and cleanup rules |
Good patterns are like the habits of a tidy workshop: tools return to labelled places, dangerous equipment is locked, and each job has a checklist. Anti-patterns are the junk drawers and spare keys under the doormat that save a minute today and cause a disaster later.
20Best Practices, Common Mistakes, and Troubleshooting
A checklist of good habits, a list of beginner mistakes, and a map of what to try when builds misbehave.
Best practices
- Keep the build configuration in the same repository as the code, and review changes to it.
- Give every step a clear id and a single purpose.
- Pin builder versions and base images, and update them on purpose with tests.
- Use dedicated, minimal service accounts and Secret Manager for every secret.
- Run fast checks first and independent steps in parallel.
- Cache layers and dependencies, but run an uncached build regularly.
- Tag images with commit identifiers and deploy immutable versions.
- Set timeouts for steps and for the whole build.
- Use file filters on triggers to avoid pointless builds.
- Send failures of important branches to the people who can fix them.
- Record provenance and consider enforcing it at deployment.
- Set budget alerts and clean up old artifacts.
Common beginner mistakes
Forgetting to save results
The image is built but never pushed, and disappears with the machine.
Missing permissions
The build account cannot push to the registry or deploy, so late steps fail.
Wrong working folder
A step runs in the wrong directory, so it cannot find the files it expects.
Huge source upload
Sending the whole folder, including large unneeded files, wastes time. Use an ignore file.
Assuming local equals cloud
A build that works on a laptop may rely on tools or files that the clean build machine does not have.
Missing logging choice
Builds with a custom service account fail because no logging option was selected.
Troubleshooting guide
| Symptom | Likely causes | What to try |
|---|---|---|
| Permission denied when pushing an image | Service account lacks registry writer role, or wrong repository path | Check the account, its roles, and the exact image name and region |
| Step fails but works locally | Different tool versions, missing files, different environment | Reproduce inside the same builder image; check the workspace contents |
| Build never starts | Trigger filters do not match, repository not connected, approval waiting | Review trigger settings, branch patterns, and connection status |
| Long wait before running | Concurrency limit or small private pool | Check quotas, add pool capacity, request limit increases |
| Timeout | Slow step, hanging process, small machine | Find the slow step, add step timeouts, use a larger machine or caching |
| Cannot reach internal system | Default pool has no private network access | Use a private pool connected to the network |
| Cannot download packages in a private pool | Outbound internet blocked | Provide a mirror or a controlled gateway route |
| Secret value missing | Wrong secret name, version, or access role | Check the available secrets section and the account’s access |
| Endless build loop | Build commits changes that retrigger it | Add file filters or a skip marker in the commit message |
| Image differs from expectation | Stale cache or moving base tag | Rebuild without cache and pin base images |
Always read the first error in the log, not the last. Later errors are often just consequences of the first one, like a row of dominoes.
21Testing, Quality Gates, and Rollbacks
Automation is only as good as the checks it runs. A pipeline should make bad changes hard to ship and bad releases easy to undo.
Layers of checks
| Layer | What it checks | Speed |
|---|---|---|
| Style and static analysis | Formatting, suspicious patterns, simple bugs | Very fast |
| Unit tests | Small pieces of code on their own | Fast |
| Dependency and image scanning | Known weaknesses in libraries and packages | Fast to medium |
| Integration tests | Several parts working together | Medium |
| End-to-end tests | The whole application, as a user would use it | Slow |
| Performance and load tests | Speed and capacity under stress | Slow, often run less often |
| Post-deployment checks | Health of the new version in a real environment | Ongoing |
Put fast checks early so most failures are found within a minute or two. Run the slow checks later or in separate pipelines, so everyday feedback stays quick.
Quality gates
A quality gate is a rule that must be satisfied before the pipeline continues. Examples: all tests pass, no serious vulnerabilities, code coverage does not fall below an agreed level, a person approves, or the new version stays healthy during a canary phase.
stateDiagram-v2
[*] --> Building
Building --> Testing: image built
Testing --> Staging: all checks pass
Testing --> Rejected: a check fails
Staging --> AwaitingApproval: staging healthy
AwaitingApproval --> Production: approved
AwaitingApproval --> Rejected: declined
Production --> Monitoring: released
Monitoring --> Stable: no problems
Monitoring --> RolledBack: errors detected
RolledBack --> [*]
Stable --> [*]
Rejected --> [*]
Rollback: the undo button
Even with excellent testing, some problems only show in real use. Plan for this from the start.
- Keep previous images in the registry so you can redeploy an earlier, known-good version quickly.
- Deploy by immutable tag or digest, so “go back” has an exact target.
- Use gradual release strategies, such as canary, to limit how many users see a bad version.
- Be careful with database changes. Make them backward compatible, so the old version still works if you roll back.
- Practice rollbacks before you need them.
Quality gates are the airport checks before a flight: ticket check, security, passport, boarding pass. Each is quick on its own, and together they stop most problems before the plane leaves the ground. A rollback is the plane’s ability to turn back if something looks wrong in the air.
Changes to data structures are the hardest to undo. Deploying new code is easy to reverse, but a database change that deletes a column is not. Plan these in small, reversible stages.
Flaky tests: the trust killer
A flaky test is a test that sometimes passes and sometimes fails on the same code, usually because of timing, shared data, or a dependence on an outside service. Flaky tests are poisonous for automation. After a few false alarms people start pressing “run again” without thinking, and eventually they ignore real failures too. Track which tests fail unpredictably, fix the cause, or move them aside until they are repaired. A smaller set of tests that everyone trusts is worth more than a large set that everyone doubts.
Test environments
Tests that need a database or another service can start small temporary copies inside the build, for example containers running beside the step, so the test starts from a known state and leaves nothing behind. This keeps tests independent and avoids the common trouble of several builds sharing one test database and disturbing each other.
22Real-World Scenarios and a Decision Record
These illustrative situations show how the ideas combine. They are examples to learn from, not claims about any real company.
Scenario 1: A small team with a web application
Need: Four developers want every merged change tested and live within minutes.
Approach: One trigger on the main branch runs tests, builds an image tagged with the commit identifier, pushes it to Artifact Registry, and deploys to Cloud Run. Pull requests run tests only.
Lesson: A short recipe and the default pool are enough. Start simple and add stages only when pain appears.
Scenario 2: Many services in one repository
Need: A single repository holds twenty small services, and building all of them for every change is wasteful.
Approach: One trigger per service, each with included-file filters pointing at that service’s folder, each using a shared recipe with a substitution for the service name.
Lesson: File filters and substitutions give you many pipelines from one recipe.
Scenario 3: A regulated company with private systems
Need: Builds must reach an internal package server, cannot reach the open internet, and every release needs an audit trail.
Approach: A private pool connected to the company network, a controlled mirror for dependencies, per-pipeline service accounts, provenance recording, Binary Authorization at deployment, and manual approval before production.
Lesson: Security requirements shape the pool, the identities, and the gates more than the build recipe itself.
Scenario 4: A static website
Need: A content team wants their site rebuilt and published whenever the content repository changes.
Approach: A trigger runs the site generator, copies the output to a Cloud Storage bucket as an artifact, and clears the cache of the content delivery network.
Lesson: Cloud Build is not only for containers. Any repeatable, scripted job fits.
An example decision record
Context
A company with about thirty developers runs services on Cloud Run and GKE. Their old build server is slow, needs weekly patching, and sometimes fails when many people merge at once. They also want records showing what code produced each production image.
Decision
Move builds to Cloud Build using the default pool for ordinary services and a private pool for services that need internal network access. Store the recipe in each repository. Use Artifact Registry with commit-tagged images, dedicated service accounts per pipeline, Secret Manager for credentials, and Cloud Deploy for promotion to production with approval.
Alternatives considered
Keeping Jenkins was rejected due to the ongoing maintenance load. Moving all pipelines to the code host’s own automation was considered, but the team preferred keeping build and deployment steps close to their Google Cloud resources and identity controls.
Consequences
No build servers to operate and automatic scaling during busy periods. Developers must learn the recipe format and manage service account permissions with care. Costs move from fixed servers to usage-based billing, so the team sets budget alerts and reviews build durations monthly.
Scenario 5: A mobile and backend team
Need: A team ships a mobile app and its backend and wants both tested together before any release.
Approach: Separate triggers build the backend image and the mobile package, run in parallel, and store test reports as artifacts. A final step collects the results, and only when both succeed is a release record created for approval.
Lesson: Pipelines can be joined by events, and artifacts such as reports give reviewers evidence instead of promises.
23Frequently Asked Questions
Short answers to the questions people ask most.
No. Containers are its natural fit, since each step is a container, but the tasks themselves can be anything: compile code, run tests, build packages, publish websites, or run infrastructure tools.
A little helps, because images and containers are central. But buildpacks can create images without you writing image instructions, and many steps simply use existing tool containers.
Yes. You can connect repositories from popular hosts and create triggers on pushes, tags, and pull requests. The connection steps depend on the host and have evolved, so follow the current instructions.
Every build has a timeout. There is a default that suits most builds and a much longer maximum, both of which you should confirm in the documentation. Set your own sensible value so stuck builds stop early.
Yes. Give steps ids and tell each which steps it must wait for. Steps without a dependency on each other start together, which can greatly shorten the build.
The build machine is deleted at the end, so you must save results on purpose. Images go to Artifact Registry, other files go to Cloud Storage, and logs go to Cloud Logging or storage buckets.
Store them in Secret Manager, grant access only to the build’s service account, and expose them only to the specific steps that need them. Never write them in the recipe or print them in logs.
It is a set of build machines dedicated to your project and connectable to your private network. You need one when builds must reach internal systems, or when you need stricter isolation, special machine sizes, or control over outbound traffic.
Cloud Build runs the build and test tasks. Cloud Deploy manages release stages and promotions across environments, with approvals and rollback. They work well together, and small projects can use Cloud Build alone.
Yes. The command-line tool can send your local folder and recipe to Cloud Build for a one-off run. This is handy for testing a recipe, though production releases should come from triggers on reviewed code.
Skip unnecessary builds with file filters, cache work, run steps in parallel, pick the right machine size, set timeouts, and set budget alerts. Measure before and after each change.
The build machine is clean. Your laptop may have tools, files, or settings that the clean machine lacks. Run the failing step inside the same builder image to reproduce the problem.
It offers useful features such as provenance records, private pools, tight identity control, and integration with vulnerability scanning and Binary Authorization. Real security still depends on how you configure and review your pipelines.
Yes, because a step can run any tool, including those that talk to other clouds or servers. It is most convenient for Google Cloud targets, but it is not limited to them.
Create a tiny recipe that runs your tests, then add an image build and a push to Artifact Registry, then a trigger on your main branch, and finally a deploy step. Improve speed and security after the basics work.
Each push can start its own build, and builds run independently on separate machines. If you reach the concurrency limit, extra builds wait in the queue. For deployments, use stage controls so two builds do not overwrite each other’s release.
It can, if its account has permission, but be careful. A build that commits back may start another build in an endless loop. Use file filters or skip markers, and prefer not to write back unless there is a strong reason.
Not necessarily. Many teams use one recipe for checks on every change, another for building release images, and another for deployment. Smaller recipes are easier to read, test, and secure, and each can have its own permissions.
Run it manually from the command-line tool against a test project or a test branch, using a service account that cannot touch production. Only when it behaves as expected should you attach it to a trigger.
Tag images with the commit identifier, deploy by digest, and keep the build record. From the running service you can then find the image, the build that made it, and the exact commit.
24Summary and Key Takeaways
You began with the idea of an automatic robot baker and ended with secure, fast, well-monitored delivery pipelines. Here is the journey in a few lines.
Cloud Build is Google Cloud’s serverless CI/CD engine. A recipe file lists steps, each run in a container on a fresh machine that disappears afterward. Triggers start builds automatically when code changes. Images and files must be saved deliberately to Artifact Registry or Cloud Storage. Substitutions make recipes reusable, and Secret Manager keeps sensitive values out of them. Parallel steps, caching, and the right machine size make builds fast, while private pools let builds reach internal networks. Cloud Deploy and release strategies carry the result safely to users, and monitoring, quality gates, and rollbacks protect them when something goes wrong. Throughout, narrow permissions, pinned tools, and signed provenance protect the software supply chain.
Because defaults, limits, free allowances, prices, and connection methods change from time to time, confirm the current details in the official Google Cloud documentation before you finalize your design.
Key Takeaways
- Cloud Build runs the steps of your recipe in containers on clean, temporary machines, so results are repeatable and there are no build servers to manage.
- Keep the recipe in the repository, use triggers with sensible filters, and save images and files on purpose, because the machine is deleted afterward.
- Make builds fast by running independent steps in parallel, caching carefully, trimming what you upload, and choosing the right machine size.
- Use dedicated, minimal service accounts, Secret Manager, pinned builders, and provenance to protect the software supply chain.
- Use private pools when builds must reach internal systems or need stronger isolation, and plan how they will fetch dependencies.
- Build once and promote the same image through staging and production, with quality gates, approvals, and a practiced rollback.
- Watch duration, queue time, success rate, and cost, and set budget and failure alerts so nothing surprises you.