Storing build artifacts in Cloud Storage Stay organized with collections Save and categorize content based on your preferences.
This page explains how you can store build artifacts in Cloud Storage.
We recommend using Artifact Registry for storing build artifacts. Artifact Registry is aGoogle Cloud product that you can integrate with Cloud Buildto securely store and manage your artifacts in private or public repositories.Storing artifacts in Artifact Registry enables you to:
- Manage container metadata and scan for container vulnerabilities withArtifact Analysis.
- Enforce deployment policies withBinary Authorization.
- Use image streaming in Google Kubernetes Engine,which is particularly beneficial for large container images.
For instructions on configuring Cloud Build to store packages and imagesfrom your builds in Artifact Registry, seeStore artifacts in Artifact Registry.
Storing artifacts in Cloud Storage
To store non-container artifacts in Cloud Storage, add anartifactsfield in your build config file with the location of the bucket to store theartifact and the path to one or more artifacts:
YAML
artifacts:objects:location:[STORAGE_LOCATION]paths:[[ARTIFACT_PATH],[ARTIFACT_PATH],...]Where,
[STORAGE_LOCATION]: A Cloud Storage bucket or a folder within thebucket where Cloud Build must store the artifact, such asgs://mybucketorgs://mybucket/myproject/builds. To find the namesof existing buckets, seelist bucketsorcreate a new bucket.[ARTIFACT_PATH]: Path to one or more artifacts.[ARTIFACT_PATH]isrelative to your working directory. This can be either/workspace,which is Cloud Build's default working directory or the workingdirectory you set using thedirfield.
JSON
{"artifacts":{"objects":{"location":["[STORAGE_LOCATION]"],"paths":[["[ARTIFACT_PATH]"],["[ARTIFACT_PATH]"],"..."]}}}Where,
[STORAGE_LOCATION]: A Cloud Storage bucket or a folder within thebucket where Cloud Build must store the artifact, such asgs://mybucketorgs://mybucket/myproject/builds. To find the names ofexisting buckets, seelist buckets orcreate a new bucket.[ARTIFACT_PATH]: Path to one or more artifacts.[ARTIFACT_PATH]isrelative to your working directory. This can be either/workspace,which is Cloud Build's default working directory or the workingdirectory you set using thedirfield.
Note the following caveats when storing artifacts in Cloud Storage:
You can specify only one bucket to upload the artifacts and you must be theowner of the bucket. You can specify a valid directory path in the bucket.
You can upload any number of artifacts, but you can specify only up to onehundred artifact paths.
If you upload an artifact to a bucket that already has an artifact with the samename, the new artifact will replace the existing artifact. You can enableObject Versioning for your bucket if youdon't want the newer artifact to replace an existing artifact with the samename.
After the build completes successfully, you can find the upload results in theJSON manifest file located at[STORAGE_LOCATION]/artifacts-$BUILD_ID.json.
The JSON manifest file has the following fields:
location: this specifies the location in Cloud Storage where anartifact is stored and is of the formgs://[STORAGE_LOCATION]/[FILE_NAME]#[GENERATION_NUMBER]. You can use thegeneration number to uniquelyidentify a version of the data in Cloud Storage bucket.file_hash: this specifies the hash type and the value. The hash type isalways 2, which specifies that MD5 hash was performed.
Artifacts examples
The following examples show how you can use theArtifacts field in a buildconfig file. In all of these examples replace[VALUES_IN_BRACKETS] with theappropriate values.
Uploading files and folders
The build config file below uploadshelloworld.class tothegs://[STORAGE_LOCATION]/:
YAML
steps:-name:'gcr.io/cloud-builders/javac'args:['HelloWorld.java']artifacts:objects:location:'gs://[STORAGE_LOCATION]/'paths:['HelloWorld.class']JSON
{"steps":[{"name":"gcr.io/cloud-builders/javac","args":["HelloWorld.java"]}],"artifacts":{"objects":{"location":"gs://[STORAGE_LOCATION]/","paths":["HelloWorld.class"]}}}To upload more than one artifact, specify the path to each artifact separated bya comma. The following example uploadsHelloWorld.java,HelloWorld.class,andcloudbuild.yaml togs://[STORAGE_LOCATION]/:
YAML
steps:-name:'gcr.io/cloud-builders/javac'args:['HelloWorld.java']artifacts:objects:location:'gs://[STORAGE_LOCATION]/'paths:['HelloWorld.java','HelloWorld.class','cloudbuild.yaml']JSON
{"steps":[{"name":"gcr.io/cloud-builders/javac","args":["HelloWorld.java"]}],"artifacts":{"objects":{"location":"gs://[STORAGE_LOCATION]/","paths":["HelloWorld.java","HelloWorld.class","cloudbuild.yaml"]}}}You can also upload the artifacts to a valid directory path in the bucket. Thefollowing example uploadsHelloWorld.java andHelloWorld.class togs://[BUCKET_NAME]/[FOLDER_NAME]:
YAML
steps:-name:'gcr.io/cloud-builders/javac'args:['HelloWorld.java']artifacts:objects:location:'gs://[BUCKET_NAME]/[FOLDER_NAME]'paths:['HelloWorld.java','HelloWorld.class']JSON
{"steps":[{"name":"gcr.io/cloud-builders/javac","args":["HelloWorld.java"]}],"artifacts":{"objects":{"location":"gs://[BUCKET_NAME]/[FOLDER_NAME]","paths":["HelloWorld.java","HelloWorld.class"]}}}Using wildcard characters to upload more than one artifact
When uploading multiple artifacts, you can usewildcard characters inpaths to specify multiplefiles.
The following example takes as an argument a file namedclasses, whichcontains the names of the.java files to compile. It then uploads any.classfile to the specified Cloud Storage bucket:
YAML
steps:-name:'gcr.io/cloud-builders/javac'args:['@classes']artifacts:objects:location:'gs://[STORAGE_LOCATION]/'paths:['*.class']JSON
{"steps":[{"name":"gcr.io/cloud-builders/javac","args":["@classes"]}],"artifacts":{"objects":{"location":"gs://[STORAGE_LOCATION]/","paths":["*.class"]}}}Using substitution variables in the bucket location
You can usesubstitutionvariablesto specify a folder within the Cloud Storage bucket. If the folder you'vespecified doesn't exist, Cloud Build will create it for you.
The example below uploads the artifacts to a Cloud Storage path thatincludes the name of your Google Cloud project from which the build was run(such as gs://mybucket/myproject/):
YAML
steps:-name:'gcr.io/cloud-builders/javac'args:['@classes']artifacts:objects:location:'gs://[BUCKET_NAME]/$PROJECT_ID'paths:['helloworld.class']JSON
{"steps":[{"name":"gcr.io/cloud-builders/javac","args":["@classes"]}],"artifacts":{"objects":{"location":"gs://[BUCKET_NAME]/$PROJECT_ID","paths":["helloworld.class"]}}}What's next
- Learn how tobuild
Goprojects. - Learn how to start a buildmanually andusing triggers.
- Learn how totroubleshoot build errors.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2026-02-19 UTC.