Almacenar artefactos de compilación en Cloud Storage
Organízate con las colecciones
Guarda y clasifica el contenido según tus preferencias.
En esta página se explica cómo puedes almacenar artefactos de compilación en Cloud Storage.
Te recomendamos que uses Artifact Registry para almacenar artefactos de compilación. Artifact Registry es unGoogle Cloud producto que puedes integrar con Cloud Build para almacenar y gestionar de forma segura tus artefactos en repositorios privados o públicos.
Almacenar artefactos en Artifact Registry te permite hacer lo siguiente:
Gestiona los metadatos de los contenedores y busca vulnerabilidades en ellos con Artifact Analysis.
Para obtener instrucciones sobre cómo configurar Cloud Build para almacenar paquetes e imágenes de tus compilaciones en Artifact Registry, consulta Almacenar artefactos en Artifact Registry.
Almacenar artefactos en Cloud Storage
Para almacenar artefactos que no sean contenedores en Cloud Storage, añade un campo artifacts
en el archivo de configuración de compilación con la ubicación del segmento en el que se va a almacenar el artefacto y la ruta a uno o varios artefactos:
[STORAGE_LOCATION]: un segmento de Cloud Storage o una carpeta del segmento en el que Cloud Build debe almacenar el artefacto, como gs://mybucket o gs://mybucket/myproject/builds. Para ver los nombres de los segmentos, consulta Listar segmentos o Crear un segmento.
[ARTIFACT_PATH]: ruta a uno o varios artefactos. [ARTIFACT_PATH] es
relativa a tu directorio de trabajo. Puede ser /workspace, que es el directorio de trabajo predeterminado de Cloud Build, o el directorio de trabajo que hayas definido con el campo dir.
[STORAGE_LOCATION]: un segmento de Cloud Storage o una carpeta del segmento en el que Cloud Build debe almacenar el artefacto, como gs://mybucket o gs://mybucket/myproject/builds. Para ver los nombres de los segmentos ya creados, consulta listar segmentos o crear un segmento.
[ARTIFACT_PATH]: ruta a uno o varios artefactos. [ARTIFACT_PATH] es
relativa a tu directorio de trabajo. Puede ser /workspace, que es el directorio de trabajo predeterminado de Cloud Build, o el directorio de trabajo que hayas definido con el campo dir.
Ten en cuenta las siguientes advertencias al almacenar artefactos en Cloud Storage:
Solo puedes especificar un contenedor para subir los artefactos y debes ser el propietario del contenedor. Puede especificar una ruta de directorio válida en el contenedor.
Puedes subir tantos artefactos como quieras, pero solo puedes especificar hasta cien rutas de artefactos.
Si sube un artefacto a un bucket que ya tiene un artefacto con el mismo nombre, el nuevo artefacto sustituirá al anterior. Puede habilitar Versiones de objetos en su cubo si no quiere que el artefacto más reciente sustituya a un artefacto con el mismo nombre.
Una vez que la compilación se haya completado correctamente, podrá consultar los resultados de la subida en el archivo de manifiesto JSON, que se encuentra en [STORAGE_LOCATION]/artifacts-$BUILD_ID.json.
El archivo de manifiesto JSON tiene los siguientes campos:
location: especifica la ubicación de Cloud Storage donde se almacena un artefacto y tiene el formato gs://[STORAGE_LOCATION]/[FILE_NAME]#[GENERATION_NUMBER]. Puedes usar el número de generación para identificar de forma única una versión de los datos en un segmento de Cloud Storage.
file_hash: especifica el tipo de hash y el valor. El tipo de hash siempre es 2, lo que especifica que se ha realizado un hash MD5.
Ejemplos de artefactos
En los siguientes ejemplos se muestra cómo puede usar el campo Artifacts en un archivo de configuración de compilación. En todos estos ejemplos, sustituye [VALUES_IN_BRACKETS] por los valores correspondientes.
Subir archivos y carpetas
El archivo de configuración de compilación que se muestra a continuación sube helloworld.class a gs://[STORAGE_LOCATION]/:
Para subir más de un artefacto, especifica la ruta de cada artefacto separada por una coma. En el siguiente ejemplo se suben HelloWorld.java, HelloWorld.class y cloudbuild.yaml a gs://[STORAGE_LOCATION]/:
También puede subir los artefactos a una ruta de directorio válida en el segmento. En el siguiente ejemplo se suben HelloWorld.java y HelloWorld.class a gs://[BUCKET_NAME]/[FOLDER_NAME]:
Usar caracteres comodín para subir más de un artefacto
Cuando subas varios artefactos, puedes usar caracteres comodín en paths para especificar varios archivos.
En el siguiente ejemplo, se toma como argumento un archivo llamado classes, que contiene los nombres de los archivos .java que se van a compilar. A continuación, sube cualquier .class
archivo al segmento de Cloud Storage especificado:
Usar variables de sustitución en la ubicación del contenedor
Puedes usar variables de sustitución
para especificar una carpeta dentro del segmento de Cloud Storage. Si la carpeta que has especificado no existe, Cloud Build la creará.
En el ejemplo siguiente se suben los artefactos a una ruta de Cloud Storage que incluye el nombre del proyecto desde el que se ha ejecutado la compilación (por ejemplo, gs://mybucket/myproject/): Google Cloud
[[["Es fácil de entender","easyToUnderstand","thumb-up"],["Me ofreció una solución al problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Es difícil de entender","hardToUnderstand","thumb-down"],["La información o el código de muestra no son correctos","incorrectInformationOrSampleCode","thumb-down"],["Me faltan las muestras o la información que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 2025-08-21 (UTC)."],[[["\u003cp\u003eThis document explains how to store non-container build artifacts in Cloud Storage by adding an \u003ccode\u003eartifacts\u003c/code\u003e field to your build config file, which includes the storage location and artifact paths.\u003c/p\u003e\n"],["\u003cp\u003eWhen storing artifacts in Cloud Storage, you can only specify one bucket, you must be the owner, you can upload up to one hundred artifact paths, and new artifacts with the same name will replace the old one unless object versioning is enabled.\u003c/p\u003e\n"],["\u003cp\u003eThe build's upload results are stored in a JSON manifest file with the \u003ccode\u003elocation\u003c/code\u003e of the artifact and its \u003ccode\u003efile_hash\u003c/code\u003e available once the build is successful.\u003c/p\u003e\n"],["\u003cp\u003eYou can upload single or multiple artifacts, including folders, using specified paths or wildcard characters in the build configuration.\u003c/p\u003e\n"],["\u003cp\u003eThe storage location in Cloud Storage can include substitution variables, allowing for dynamic path creation, like including the project ID in the folder name.\u003c/p\u003e\n"]]],[],null,["# Storing build artifacts in Cloud Storage\n\nThis page explains how you can store build artifacts in Cloud Storage.\n\nWe recommend using Artifact Registry for storing build artifacts. Artifact Registry is a\nGoogle Cloud product that you can integrate with Cloud Build\nto securely store and manage your artifacts in private or public repositories.\nStoring artifacts in Artifact Registry enables you to:\n\n- Manage container metadata and scan for container vulnerabilities with [Artifact Analysis](/artifact-analysis/docs).\n- Enforce deployment policies with [Binary Authorization](/binary-authorization/docs).\n- [Use image streaming in Google Kubernetes Engine](/kubernetes-engine/docs/how-to/image-streaming), which is particularly beneficial for large container images.\n\nFor instructions on configuring Cloud Build to store packages and images\nfrom your builds in Artifact Registry, see\n[Store artifacts in Artifact Registry](/build/docs/building/store-artifacts-in-artifact-registry).\n\nStoring artifacts in Cloud Storage\n----------------------------------\n\n**To store non-container artifacts in Cloud Storage** , add an `artifacts`\nfield in your build config file with the location of the bucket to store the\nartifact and the path to one or more artifacts: \n\n### YAML\n\n artifacts:\n objects:\n location: [STORAGE_LOCATION]\n paths: [[ARTIFACT_PATH],[ARTIFACT_PATH], ...]\n\nWhere,\n\n- `[STORAGE_LOCATION]`: A Cloud Storage bucket or a folder within the bucket where Cloud Build must store the artifact, such as `gs://mybucket` or `gs://mybucket/myproject/builds`. To find the names of existing buckets, see [list buckets](/storage/docs/listing-buckets) or [create a new bucket](/storage/docs/creating-buckets).\n- `[ARTIFACT_PATH]`: Path to one or more artifacts. `[ARTIFACT_PATH]` is relative to your working directory. This can be either `/workspace`, which is Cloud Build's default working directory or the working directory you set using the [`dir`](/build/docs/build-config-file-schema#build_steps) field.\n\n### JSON\n\n {\n \"artifacts\": {\n \"objects\": {\n \"location\": [\n \"[STORAGE_LOCATION]\"\n ],\n \"paths\": [\n [\n \"[ARTIFACT_PATH]\"\n ],\n [\n \"[ARTIFACT_PATH]\"\n ],\n \"...\"\n ]\n }\n }\n }\n\nWhere,\n\n- `[STORAGE_LOCATION]`: A Cloud Storage bucket or a folder within the bucket where Cloud Build must store the artifact, such as `gs://mybucket` or `gs://mybucket/myproject/builds`. To find the names of existing buckets, see [list buckets](/storage/docs/listing-buckets) or [create a new bucket](/storage/docs/creating-buckets).\n- `[ARTIFACT_PATH]`: Path to one or more artifacts. `[ARTIFACT_PATH]` is relative to your working directory. This can be either `/workspace`, which is Cloud Build's default working directory or the working directory you set using the [`dir`](/build/docs/build-config-file-schema#build_steps) field.\n\nNote the following caveats when storing artifacts in Cloud Storage:\n\n- You can specify only one bucket to upload the artifacts and you must be the\n owner of the bucket. You can specify a valid directory path in the bucket.\n\n- You can upload any number of artifacts, but you can specify only up to one\n hundred artifact paths.\n\n- If you upload an artifact to a bucket that already has an artifact with the same\n name, the new artifact will replace the existing artifact. You can enable\n [Object Versioning](/storage/docs/object-versioning) for your bucket if you\n don't want the newer artifact to replace an existing artifact with the same\n name.\n\nAfter the build completes successfully, you can find the upload results in the\nJSON manifest file located at `[STORAGE_LOCATION]/artifacts-$BUILD_ID.json`.\n\nThe JSON manifest file has the following fields:\n\n- `location`: this specifies the location in Cloud Storage where an artifact is stored and is of the form `gs://[STORAGE_LOCATION]/[FILE_NAME]#[GENERATION_NUMBER]`. You can use the [generation number](/storage/docs/metadata#generation-number) to uniquely identify a version of the data in Cloud Storage bucket.\n- `file_hash`: this specifies the hash type and the value. The hash type is always 2, which specifies that MD5 hash was performed.\n\nArtifacts examples\n------------------\n\nThe following examples show how you can use the `Artifacts` field in a build\nconfig file. In all of these examples replace `[VALUES_IN_BRACKETS]` with the\nappropriate values.\n\n### Uploading files and folders\n\nThe build config file below uploads `helloworld.class` to\nthe`gs://[STORAGE_LOCATION]/`: \n\n### YAML\n\n steps:\n - name: 'gcr.io/cloud-builders/javac'\n args: ['HelloWorld.java']\n artifacts:\n objects:\n location: 'gs://[STORAGE_LOCATION]/'\n paths: ['HelloWorld.class']\n\n### JSON\n\n {\n \"steps\": [\n {\n \"name\": \"gcr.io/cloud-builders/javac\",\n \"args\": [\n \"HelloWorld.java\"\n ]\n }\n ],\n \"artifacts\": {\n \"objects\": {\n \"location\": \"gs://[STORAGE_LOCATION]/\",\n \"paths\": [\n \"HelloWorld.class\"\n ]\n }\n }\n }\n\nTo upload more than one artifact, specify the path to each artifact separated by\na comma. The following example uploads `HelloWorld.java`, `HelloWorld.class`,\nand `cloudbuild.yaml` to `gs://[STORAGE_LOCATION]/`: \n\n### YAML\n\n steps:\n - name: 'gcr.io/cloud-builders/javac'\n args: ['HelloWorld.java']\n artifacts:\n objects:\n location: 'gs://[STORAGE_LOCATION]/'\n paths: ['HelloWorld.java', 'HelloWorld.class', 'cloudbuild.yaml']\n\n### JSON\n\n {\n \"steps\": [\n {\n \"name\": \"gcr.io/cloud-builders/javac\",\n \"args\": [\n \"HelloWorld.java\"\n ]\n }\n ],\n \"artifacts\": {\n \"objects\": {\n \"location\": \"gs://[STORAGE_LOCATION]/\",\n \"paths\": [\n \"HelloWorld.java\",\n \"HelloWorld.class\",\n \"cloudbuild.yaml\"\n ]\n }\n }\n }\n\nYou can also upload the artifacts to a valid directory path in the bucket. The\nfollowing example uploads `HelloWorld.java` and `HelloWorld.class` to\n`gs://[BUCKET_NAME]/[FOLDER_NAME]`: \n\n### YAML\n\n steps:\n - name: 'gcr.io/cloud-builders/javac'\n args: ['HelloWorld.java']\n artifacts:\n objects:\n location: 'gs://[BUCKET_NAME]/[FOLDER_NAME]'\n paths: ['HelloWorld.java', 'HelloWorld.class']\n\n### JSON\n\n {\n \"steps\": [\n {\n \"name\": \"gcr.io/cloud-builders/javac\",\n \"args\": [\n \"HelloWorld.java\"\n ]\n }\n ],\n \"artifacts\": {\n \"objects\": {\n \"location\": \"gs://[BUCKET_NAME]/[FOLDER_NAME]\",\n \"paths\": [\n \"HelloWorld.java\",\n \"HelloWorld.class\"\n ]\n }\n }\n }\n\n### Using wildcard characters to upload more than one artifact\n\nWhen uploading multiple artifacts, you can use\n[wildcard characters](/storage/docs/wildcards) in `paths` to specify multiple\nfiles.\n\nThe following example takes as an argument a file named `classes`, which\ncontains the names of the `.java` files to compile. It then uploads any `.class`\nfile to the specified Cloud Storage bucket: \n\n### YAML\n\n steps:\n - name: 'gcr.io/cloud-builders/javac'\n args: ['@classes']\n artifacts:\n objects:\n location: 'gs://[STORAGE_LOCATION]/'\n paths: ['*.class']\n\n### JSON\n\n {\n \"steps\": [\n {\n \"name\": \"gcr.io/cloud-builders/javac\",\n \"args\": [\n \"@classes\"\n ]\n }\n ],\n \"artifacts\": {\n \"objects\": {\n \"location\": \"gs://[STORAGE_LOCATION]/\",\n \"paths\": [\n \"*.class\"\n ]\n }\n }\n }\n\n### Using substitution variables in the bucket location\n\nYou can use [substitution\nvariables](/build/docs/configuring-builds/substitute-variable-values)\nto specify a folder within the Cloud Storage bucket. If the folder you've\nspecified doesn't exist, Cloud Build will create it for you.\n\nThe example below uploads the artifacts to a Cloud Storage path that\nincludes the name of your Google Cloud project from which the build was run\n(such as gs://mybucket/myproject/): \n\n### YAML\n\n steps:\n - name: 'gcr.io/cloud-builders/javac'\n args: ['@classes']\n artifacts:\n objects:\n location: 'gs://[BUCKET_NAME]/$PROJECT_ID'\n paths: ['helloworld.class']\n\n### JSON\n\n {\n \"steps\": [\n {\n \"name\": \"gcr.io/cloud-builders/javac\",\n \"args\": [\n \"@classes\"\n ]\n }\n ],\n \"artifacts\": {\n \"objects\": {\n \"location\": \"gs://[BUCKET_NAME]/$PROJECT_ID\",\n \"paths\": [\n \"helloworld.class\"\n ]\n }\n }\n }\n\nWhat's next\n-----------\n\n- Learn how to [build `Go` projects](/build/docs/building/build-go).\n- Learn how to start a build [manually](/build/docs/running-builds/start-build-manually) and [using triggers](/build/docs/running-builds/automate-builds).\n- Learn how to [troubleshoot build errors](/build/docs/troubleshooting)."]]