October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
Mountain View desk6 min

How to Run Automated Tests with Google Cloud Build

Configure a Cloud Build test step, keep failures from reaching later steps, optionally store JUnit XML in Cloud Storage, and automate runs with a repository trigger.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To run automated tests with Google Cloud Build, add a build step to cloudbuild.yaml that invokes your project’s test command in a container with the right runtime and tools. Put that step before packaging, publishing, or deployment steps so a failed test stops the build before those actions run. You can start the build manually or connect it to a repository trigger.

How Cloud Build runs tests

Cloud Build reads a YAML or JSON build configuration and runs its steps in containers. A test is an ordinary build step: choose an image containing the required runtime and tooling, then invoke the command your project already uses. The same configuration can run dependency setup, unit tests, static analysis, integration tests, and artifact creation.

As an Amazon Associate I earn from qualifying purchases.

Build steps run serially by default. If tests are a release gate, place them before any step that builds or publishes a release artifact or deploys it. See Google Cloud’s Cloud Build overview.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Add a test step to cloudbuild.yaml

Create cloudbuild.yaml in your project root. The smallest useful configuration has a step with a runtime image and a test command. Match the image and dependency setup to your application; a floating image tag such as latest can change over time, so pin a tag when reproducible environments matter.

steps:
  - name: 'python'
    entrypoint: 'python'
    args: ['-m', 'pytest']

This example runs pytest and relies on dependencies being available in the image or installed by an earlier step. Adapt the setup to your project. Google’s guide to running tests documents language-specific patterns.

Use the test command for your language

Python

Run pytest through Python’s module interface. To have pytest write a JUnit XML report as well as return a test status, add the report option:

steps:
  - name: 'python'
    entrypoint: 'python'
    args: ['-m', 'pytest', '--junitxml=${SHORT_SHA}_test_log.xml']

Node.js

If your package.json defines a test script, install dependencies and run it in a Node.js image:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
steps:
  - name: 'node'
    entrypoint: 'npm'
    args: ['install']
  - name: 'node'
    entrypoint: 'npm'
    args: ['test']

Use the dependency installation process appropriate for your project and lockfile; the important part is that the test step has the required dependencies and invokes the project’s test script.

Go

The basic Go test step invokes go test. Google’s example pipes verbose output through go-junit-report when an XML report is wanted, using -set-exit-code so a failing test remains a failing build step. Configure the formatter and its installation for your selected image and Go toolchain; do not let a pipeline hide the test command’s nonzero exit status.

steps:
  - name: 'golang'
    entrypoint: 'go'
    args: ['test', './...']

See Google’s language examples for test steps for the documented report-generation pattern.

Keep test failures from reaching later steps

A normal test command exits unsuccessfully when tests fail, which makes its build step fail. Because steps run serially by default, later packaging, publication, or deployment steps do not run after that failure. Keep test status visible if you wrap a command in a shell script or pipeline: a wrapper that exits successfully despite failed tests defeats the gate.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For example, when piping Go test output into a report formatter, use a setup that propagates the test failure. Google’s documented Go pattern uses -set-exit-code with go-junit-report for that purpose.

Generate and store a JUnit XML report

Generating a report and storing it are separate choices. A test runner may write JUnit XML locally, but Cloud Storage persistence requires an artifact declaration in the build configuration and a valid bucket destination.

steps:
  - name: 'python'
    entrypoint: 'python'
    args: ['-m', 'pytest', '--junitxml=${SHORT_SHA}_test_log.xml']

artifacts:
  objects:
    location: 'gs://${_BUCKET_NAME}/'
    paths:
      - '${SHORT_SHA}_test_log.xml'

Before using this pattern, create the bucket and ensure the build’s service account has permission to write objects there. Google’s Python guide identifies the Cloud Storage Object Creator role among the prerequisites. A report file is an artifact you can retain separately; the build’s normal logs remain useful for diagnosing the command itself. The reviewed documentation does not establish a particular automatic report viewer or test dashboard. See Google’s report and test configuration examples and Cloud Build artifact storage documentation.

Run a build manually

Once the configuration is in the project root, submit a build with the Google Cloud CLI:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
gcloud builds submit

Cloud Build runs the configured steps and shows build details and logs in Build History. Manual submission is useful for an ad hoc run before connecting automation. If configuration values vary by run, pass user-defined substitutions:

gcloud builds submit --substitutions=_BUCKET_NAME=your-bucket

Define any user substitutions in the build configuration and replace the example bucket value with your actual destination. Built-in substitutions such as $PROJECT_ID and $SHORT_SHA can provide build-specific values. See Google’s substitutions documentation.

Run tests automatically with a repository trigger

For continuous integration, create a Cloud Build trigger tied to your repository and choose an event such as a push to a branch. Configure the trigger to use the build configuration in the repository; trigger settings can also supply substitutions. A push then starts the build, and the test step runs as part of the configured sequence.

  1. Open Cloud Build and create a build trigger.

  2. Connect or select the repository and choose the event and branch pattern that should start a build.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  3. Point the trigger at your cloudbuild.yaml configuration.

  4. Set any required trigger substitutions, such as a bucket name used for report storage.

  5. Save the trigger, push a change matching its event settings, and inspect the resulting build in Build History.

Exact console labels and trigger availability can vary with repository connection and Cloud Build configuration. Google’s Cloud Build quickstart demonstrates a push-to-branch trigger and reviewing build history.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use substitutions for changing values

Substitutions let a build configuration use values that differ between builds, such as a project identifier, commit identifier, or report bucket. Built-in variables include $PROJECT_ID and $SHORT_SHA; user-defined variables use names beginning with an underscore, such as ${_BUCKET_NAME}. Set user-defined values on a manual submission or in trigger settings, and ensure the configuration declares the variables it uses.

Substitutions are configuration values, not a substitute for handling secrets. The cited substitutions guide explains variable substitution; it does not establish a secret-management recommendation.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Inspect results and troubleshoot failures

Open the build’s details and logs through Cloud Build History or use the CLI/API to inspect the execution. The logs show which step failed and its output; a stored JUnit XML file provides a separate machine-readable result artifact if you configured storage.

Or skip the browser setup

If your pipeline also needs website screenshots, ScreenshotNeo provides a screenshot API and MCP server; it is separate from Cloud Build test execution. One GET request can return an image or PDF. For example, save a WebP screenshot with cURL:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo API documentation for request options. Cookie banners, popups, and chat widgets are removed before the shot; bot checks, blank pages, and failed loads are never billed. An MCP server lets AI agents take screenshots. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000. Sign up for ScreenshotNeo free.

Frequently Asked Questions

Does Cloud Build require a specific test framework?

No. Use the command and runtime image that fit your project; the documented examples include pytest, npm test, and go test.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Does Cloud Build automatically upload JUnit XML when a test creates it?

No. Configure an artifact destination and paths, and provide a bucket with the required write permissions.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.