Cloud Build in Google Cloud

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.

Everyday analogy

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.

0
Servers for you to set up or patch
1
Recipe file describes the whole job
Many
Builds can run at the same time

What people use it for

Build

Packaging applications

Turn source code into container images or other packages that are ready to run.

Test

Automatic checks

Run unit tests, style checks, and security scans every time code changes.

Deliver

Deploying to Google Cloud

Push new versions to Cloud Run, Google Kubernetes Engine, App Engine, and more.

Infrastructure

Applying cloud setup

Run tools that create or update cloud resources from written descriptions.

Data

Scheduled jobs

Run maintenance or data tasks in a clean environment, on a timer or on request.

Publish

Releasing packages

Create and publish libraries, documents, and mobile app files.

i
Tip

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.

Code

Source code

The human-written instructions of a program, stored as text files.

Code

Repository

A folder with a full history of the code, kept by a version control tool such as Git. Often called a repo.

Code

Commit

A saved snapshot of changes in a repository, with a message and an author.

Code

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.

Code

Pull request

A proposal to merge one branch into another, which teammates review before it is accepted.

Make

Build

The act of turning source code into something runnable, including all checks along the way.

Make

Artifact

Anything a build produces and keeps: an image, a package, a report, a downloadable file.

Make

Pipeline

A series of automated stages, such as build, test, scan, and deploy, that code passes through.

Run

Container

A lightweight, sealed box holding a program and everything it needs, so it behaves the same on any computer.

Run

Image

The frozen template from which containers are started. Think of it as a sealed meal kit.

Store

Registry

A library that stores container images so they can be fetched later. Google’s is called Artifact Registry.

Start

Trigger

A rule that says “when this happens, start that build”, such as a new commit.

Why automate at all?

By handWith automation
Steps live in someone’s memory or an old documentSteps are written in a file that everyone can read and improve
Works on one developer’s laptop, fails elsewhereAlways runs in the same clean environment
Tests are skipped when people are in a hurryTests run every single time
Releases are rare and scaryReleases are frequent, small, and boring
Mistakes are found by customersMistakes are found minutes after the change
Hard to know who released what, and whenEvery build leaves a record
Everyday analogy

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.

!
Good to know

“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.

01

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.

02

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.

03

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.

04

Hosted CI services

Cloud providers began running build machines for you, billing by the minute. No more babysitting build servers.

05

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.

06

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.
i
Tip

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.

Job

Build

One complete run of your recipe. It has a unique identifier, a status, a start time, a finish time, and logs.

Task

Step

One action inside a build. Each step runs inside its own container and does one clear job.

Tool

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.

Recipe

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.

Shared

Workspace

A shared folder that every step in a build can read and write. It is how steps pass files to each other.

Start

Trigger

A saved rule that starts builds automatically when something happens, or on request.

Fill-in

Substitution

A named placeholder in the recipe that is replaced by a real value when the build runs.

Output

Images and artifacts

The things the build keeps after it ends, because everything else is deleted along with the machine.

Place

Worker pool

The group of machines where builds run: Google’s default shared pool, or a private pool that you control.

Identity

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.

Everyday analogy

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.

!
Watch out

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"]
    
Figure 1: The main parts around Cloud Build, from a code change to a deployed application.

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.

ComponentRoleWho manages it
Cloud Build serviceAccepts builds, schedules them, records statusGoogle
Default worker poolShared machines that run buildsGoogle
Private worker poolMachines dedicated to your project, reachable from your private networkGoogle runs them, you configure them
TriggersRules that start buildsYou
Build configurationThe recipeYou
BuildersTool containers used by stepsGoogle, the community, or you
Artifact Registry and Cloud StorageLong-term storage for resultsYou
Service accountIdentity and permissions of the buildYou
Everyday analogy

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
    
Figure 2: A build from request to result. Steps run inside the worker machine, which is discarded at the end.

The stages in plain words

1

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.

2

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.

3

Queueing

The build waits for a free slot. If many builds are already running, yours stays queued until capacity is available.

4

Machine assignment

A fresh virtual machine is prepared. This includes fetching the builder images that your steps will use.

5

Source preparation

Your source code is placed into the shared workspace folder.

6

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.

7

Saving results

Images listed in the recipe are pushed to the registry. Artifacts are copied to Cloud Storage.

8

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

StatusMeaning
QueuedWaiting for a machine
WorkingSteps are running
SuccessAll steps passed and results were saved
FailureA step failed
Internal errorA problem on the service side, usually worth retrying
TimeoutThe build ran longer than its allowed time
CancelledSomeone stopped it
Everyday analogy

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.

i
Tip

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

SectionWhat it holdsWhy it matters
stepsThe ordered list of actionsThe heart of the recipe
imagesNames of container images to push to a registry when all steps succeedEnsures the final image is saved
artifactsFiles or packages to copy out of the workspace to storageKeeps test reports, packages, and other outputs
substitutionsNamed placeholders with default valuesMakes one recipe reusable
timeoutMaximum time for the whole buildStops runaway builds
optionsMachine type, disk size, logging mode, pool choice, and moreControls speed, cost, and behavior
available secretsPointers to values stored in Secret ManagerLets steps use secrets safely
service accountThe identity the build runs asControls what the build is allowed to touch
tagsLabels attached to the buildHelps search and organize history
queue time-to-liveHow long a build may wait before being droppedAvoids stale builds running late

What one step can say

Required

name

The builder image to use for the step.

Optional

args and entrypoint

The command and arguments to run. The entrypoint overrides the builder’s default program.

Optional

id

A short name for the step, so other steps can refer to it.

Optional

wait for

A list of step ids that must finish first. This lets independent steps run in parallel.

Optional

dir

Which folder inside the workspace to run in.

Optional

env

Environment variables, which are small named settings visible to the program.

Optional

secret env

Which secrets from Secret Manager this step may read.

Optional

timeout

A time limit for this one step.

Optional

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.

Everyday analogy

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.

i
Tip

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.

Google

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

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

Public images

Any public container image can be a builder, such as official language images from Docker Hub.

Yours

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

ApproachHow it worksGood for
Docker build stepUses the instructions file in your repository to assemble an imageThe most common and flexible approach
BuildpacksDetect the language of your project and assemble a secure image without you writing image instructionsTeams who want less container work
Kaniko-style buildersBuild images without needing a privileged Docker service and support layer caching in a registryFaster repeat builds with simple caching
Language-specific toolsTools for particular ecosystems that create images straight from the projectJava 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.
Everyday analogy

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.

!
Watch out

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

Code

Push to a branch

A new commit lands on a branch whose name matches a pattern, such as the main branch.

Code

Push of a tag

A release tag is created, a natural moment to build and publish a version.

Review

Pull request

A proposed change is opened or updated, so checks run before merging.

Manual

Run on request

A person presses a button or calls the programming interface. Optionally an approval can be required first.

Message

Pub/Sub event

A message arrives on a topic, for instance when an image changes or a schedule fires.

Web

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
    
Figure 3: How a trigger decides whether to start a build.

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.

Everyday analogy

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.

!
Watch out

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.

Everyday analogy

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.

KindExamples of what it gives youWho sets it
Default substitutionsThe project identifier, the build identifier, the regionCloud Build
Repository substitutionsThe commit identifier, branch name, tag name, repository name, short commit identifierCloud Build, when started by a trigger
User-defined substitutionsYour own names, such as an environment name or a deployment regionYou, 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.

Everyday analogy

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.

i
Tip

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

Images

Artifact Registry

The recommended home for container images, and also for language packages such as those for Java, Python, and JavaScript.

Files

Cloud Storage

A general file store, good for test reports, binaries, website files, and any other output.

Logs

Cloud Logging and storage buckets

Where build logs are written, depending on your logging choice.

Record

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.

TechniqueHow it helps
Image layer cachingPull the previous image first and let the image builder reuse unchanged layers. Layers are the stacked pieces of an image
Registry-based cacheBuilders such as Kaniko store layers in a registry and reuse them across builds
Dependency cachingSave downloaded libraries to Cloud Storage and restore them at the start of the next build
Smart image instructionsOrder the image instructions so that rarely changed parts come first, keeping cached layers valid for longer
Small contextIgnore unneeded files when sending source, so less is uploaded and fewer changes break the cache
Everyday analogy

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.

!
Watch out

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"]
    
Figure 4: Independent checks run side by side, and the image is built once all of them are ready.

Main speed levers

Parallel

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.

Power

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.

Reuse

Use caching

Reuse image layers and downloaded libraries instead of fetching them again.

Slim

Smaller builders and images

Fewer bytes to download means less waiting at the start of every step.

Focus

Build only what changed

Use file filters so that unrelated changes do not start builds at all.

Near

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.
Everyday analogy

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.

i
Tip

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"]
    
Figure 5: A simple way to choose between the default pool and a private pool.

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.

QuestionDefault poolPrivate pool
Set-up effortNoneCreate and configure the pool and network connection
Access to private networksNo direct accessYes, through peering or a similar private connection
Machine choiceA set of standard sizesWider choice, including larger machines
IsolationShared infrastructure managed by GoogleDedicated to your project
Outbound internet controlOpenCan be limited or blocked
BillingPer build minute by machine type, with a free allowancePer minute for the pool machines in use, with different pricing
Best forMost standard buildsRegulated, 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.

Everyday analogy

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.

!
Watch out

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
    
Figure 6: A common delivery flow, with Cloud Build making the image and Cloud Deploy managing the stages.

Where builds can deploy

Serverless

Cloud Run

Run containers without managing servers. A deploy step points the service to the new image, and Cloud Run handles rollout and scaling.

Kubernetes

Google Kubernetes Engine

Update the desired state of a cluster, so it pulls and runs the new image. Often done through release tools.

App platform

App Engine and Cloud Functions

Deploy source or packages straight to managed application platforms.

Websites

Cloud Storage and CDN

Copy built static website files to a storage bucket that serves visitors.

Servers

Virtual machines

Update machine groups with new images or startup instructions.

Infrastructure

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

StrategyHow it worksBenefitCost
Replace in placeThe new version replaces the old oneSimpleMistakes reach everyone quickly
RollingInstances are updated a few at a timeNo full downtimeTwo versions run together for a while
Blue-greenA complete new copy is started, then traffic is switchedInstant switch and easy rollbackNeeds double capacity during the switch
CanaryA small share of users gets the new version firstProblems affect few peopleMore monitoring and moving parts
Everyday analogy

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.

i
Tip

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

1

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.

2

Create the image

Earlier steps test the code, build the image, and push it with the commit identifier as its tag.

3

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.

4

Shift traffic

Traffic can move all at once, or gradually, for example ten percent first and the rest later.

5

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.

Identity

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.

Identity

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.

Secrets

Secret Manager

Keep sensitive values in a proper safe, give access only to the steps and accounts that need it, and rotate them regularly.

Network

Private pools and perimeters

Run builds inside your private network, restrict outbound traffic, and use service perimeters to reduce the risk of data leaving.

Proof

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.

Gate

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.

Scan

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.

Trace

Audit logs

Record who started builds, changed triggers, or altered permissions.

A chain you can trust

1

Protect the source

Require reviews before code is merged, and protect the main branches.

2

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.

3

Trust the tools

Pin builders to exact versions and keep approved copies in your own registry.

4

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.

5

Sign the result

Produce provenance and attestations that prove the image came from your pipeline.

6

Verify before running

Let the runtime environment accept only images that carry valid proofs.

Everyday analogy

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.

!
Watch out

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 registryWrite access to the specific repository in Artifact Registry
Write logsPermission to write to Cloud Logging, or to the chosen storage bucket
Read a secretAccess to the specific secret in Secret Manager, nothing more
Deploy to Cloud RunPermission to deploy to the service, plus permission to use the service’s identity
Update a GKE clusterLimited permission to the specific cluster or namespace
Copy files to a bucketWrite 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

Messages

Pub/Sub build events

Cloud Build publishes a message when a build changes state. Any system can listen and react.

Chat

Chat and email alerts

Small notifier programs can read those messages and post to chat tools or send email when builds fail.

Source

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.

Alerts

Monitoring alerts

Create alerts from log-based metrics, such as the number of failed builds in an hour.

What to measure

MeasureWhy it matters
Build durationSlow builds slow every developer down
Queue timeShows capacity or concurrency problems
Success rateA falling rate points to flaky tests or fragile steps
Time to fix a broken buildShows how quickly the team reacts
Cost per build and per monthPrevents surprises on the bill
Deployment frequencyA healthy sign of small, frequent releases
Change failure rateShare 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.

Everyday analogy

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.

i
Tip

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

Fewer

Filter triggers

Skip builds for changes that do not matter, such as documentation edits.

Faster

Cache and parallelize

Less time per build means a smaller bill.

Right-sized

Match machine to job

Do not use a big machine for a tiny script. Do not use a tiny machine for a huge compile.

Capped

Set timeouts

A stuck build is stopped instead of running for hours.

Tidy

Clean old images

Set cleanup rules in the registry so that thousands of old images do not pile up.

Watched

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.

Everyday analogy

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.

!
Watch out

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

ChoiceOne sideOther side
Convenience versus controlDefault pool is zero-effortPrivate pools give network control but need set-up
Speed versus costLarge machines finish soonerSmaller machines cost less per minute
Clean builds versus fast buildsClean builds are fully repeatableCaching saves time but can hide problems
Simple recipe versus flexibilityShort recipes are easy to understandMany conditions handle more cases but are harder to maintain
Managed versus self-runNo operations workSelf-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.

Everyday analogy

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

Pattern

Pipeline as code

Keep the recipe in the repository, reviewed like any other code.

Pattern

Build once, promote

Create one image and move that same image through every environment.

Pattern

Fail fast

Run the quickest checks first, such as style and unit tests, so bad changes are rejected within a minute or two.

Pattern

Parallel checks

Run independent checks side by side and join them before the build step.

Pattern

Pinned, private builders

Use fixed versions of tools, kept in your own registry.

Pattern

Separate accounts per pipeline

Each pipeline has its own minimal service account.

Pattern

Approval gates

Production deployments wait for a human approval or an automatic policy check.

Pattern

Immutable tags

Tag images with commit identifiers and never overwrite a released tag.

Pattern

Shared recipe fragments

Reuse custom builders and common steps across many projects to keep them consistent.

Anti-patterns to avoid

Anti-patternWhy it hurtsBetter approach
Secrets written into the recipeAnyone with repository access can read themUse Secret Manager and per-step access
Using the latest tag for builders or base imagesBuilds change without warningPin exact versions or digests
One giant account with owner rightsOne mistake can wreck the projectNarrow roles per pipeline
Rebuilding for each environmentProduction may differ from what was testedBuild once and promote the same image
Running every check seriallyLong waits for no reasonParallelize independent steps
Skipping tests to go fasterDefects reach usersSpeed up tests, never remove them
Ignoring flaky testsPeople stop trusting failuresFix or quarantine flaky tests quickly
Manual changes to productionNobody knows the true stateAll changes flow through the pipeline
Building untrusted pull requests with full powerAttackers can steal secretsComment control and minimal permissions
Never cleaning registriesCost and clutter grow foreverRetention and cleanup rules
Everyday analogy

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

Mistake

Forgetting to save results

The image is built but never pushed, and disappears with the machine.

Mistake

Missing permissions

The build account cannot push to the registry or deploy, so late steps fail.

Mistake

Wrong working folder

A step runs in the wrong directory, so it cannot find the files it expects.

Mistake

Huge source upload

Sending the whole folder, including large unneeded files, wastes time. Use an ignore file.

Mistake

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.

Mistake

Missing logging choice

Builds with a custom service account fail because no logging option was selected.

Troubleshooting guide

SymptomLikely causesWhat to try
Permission denied when pushing an imageService account lacks registry writer role, or wrong repository pathCheck the account, its roles, and the exact image name and region
Step fails but works locallyDifferent tool versions, missing files, different environmentReproduce inside the same builder image; check the workspace contents
Build never startsTrigger filters do not match, repository not connected, approval waitingReview trigger settings, branch patterns, and connection status
Long wait before runningConcurrency limit or small private poolCheck quotas, add pool capacity, request limit increases
TimeoutSlow step, hanging process, small machineFind the slow step, add step timeouts, use a larger machine or caching
Cannot reach internal systemDefault pool has no private network accessUse a private pool connected to the network
Cannot download packages in a private poolOutbound internet blockedProvide a mirror or a controlled gateway route
Secret value missingWrong secret name, version, or access roleCheck the available secrets section and the account’s access
Endless build loopBuild commits changes that retrigger itAdd file filters or a skip marker in the commit message
Image differs from expectationStale cache or moving base tagRebuild without cache and pin base images
i
Tip

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

LayerWhat it checksSpeed
Style and static analysisFormatting, suspicious patterns, simple bugsVery fast
Unit testsSmall pieces of code on their ownFast
Dependency and image scanningKnown weaknesses in libraries and packagesFast to medium
Integration testsSeveral parts working togetherMedium
End-to-end testsThe whole application, as a user would use itSlow
Performance and load testsSpeed and capacity under stressSlow, often run less often
Post-deployment checksHealth of the new version in a real environmentOngoing

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 --> [*]
    
Figure 7: The life of a change through gates, with a path back if the release goes wrong.

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.
Everyday analogy

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.

!
Watch out

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

ADR-01Accepted
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.

Q1 Is Cloud Build only for containers?

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.

Q2 Do I need to know Docker?

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.

Q3 Can Cloud Build work with GitHub or GitLab?

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.

Q4 How long can a build run?

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.

Q5 Can steps run at the same time?

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.

Q6 Where do my build results go?

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.

Q7 How do I keep secrets safe?

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.

Q8 What is a private pool and do I need one?

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.

Q9 What is the difference between Cloud Build and Cloud Deploy?

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.

Q10 Can I run a build from my own laptop?

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.

Q11 How do I make builds cheaper?

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.

Q12 Why does my build pass on my machine and fail in Cloud Build?

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.

Q13 Is Cloud Build good for supply chain security?

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.

Q14 Can Cloud Build deploy outside Google Cloud?

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.

Q15 Where should I start?

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.

Q16 What happens if two people push at the same time?

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.

Q17 Can a build change the repository that started it?

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.

Q18 Should one recipe do everything?

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.

Q19 How do I test a new recipe without risking production?

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.

Q20 How do I know which code is running in production?

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.

The best pipeline is the one nobody thinks about: it runs on every change, tells the truth quickly, and makes releasing software feel ordinary.

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.