Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Halaman ini menjelaskan cara menyimpan artefak build di Cloud Storage.
Sebaiknya gunakan Artifact Registry untuk menyimpan artefak build. Artifact Registry adalah produkGoogle Cloud yang dapat Anda integrasikan dengan Cloud Build untuk menyimpan dan mengelola artefak dengan aman di repositori pribadi atau publik.
Dengan menyimpan artefak di Artifact Registry, Anda dapat:
Kelola metadata container dan pindai kerentanan container dengan
Artifact Analysis.
Untuk petunjuk cara mengonfigurasi Cloud Build guna menyimpan paket dan image
dari build Anda di Artifact Registry, lihat
Menyimpan artefak di Artifact Registry.
Menyimpan artefak di Cloud Storage
Untuk menyimpan artefak non-penampung di Cloud Storage, tambahkan kolom artifacts
dalam file konfigurasi build dengan lokasi bucket untuk menyimpan
artefak dan jalur ke satu atau beberapa artefak:
[STORAGE_LOCATION]: Bucket Cloud Storage atau folder dalam
bucket tempat Cloud Build harus menyimpan artefak, seperti
gs://mybucket atau gs://mybucket/myproject/builds. Untuk menemukan nama bucket yang ada, lihat mencantumkan bucket atau membuat bucket baru.
[ARTIFACT_PATH]: Jalur ke satu atau beberapa artefak. [ARTIFACT_PATH] bersifat
relatif terhadap direktori kerja Anda. Ini dapat berupa /workspace,
yang merupakan direktori kerja default Cloud Build atau direktori kerja
yang Anda tetapkan menggunakan kolom dir.
[STORAGE_LOCATION]: Bucket Cloud Storage atau folder dalam
bucket tempat Cloud Build harus menyimpan artefak, seperti
gs://mybucket atau gs://mybucket/myproject/builds. Untuk menemukan nama
bucket yang ada, lihat mencantumkan bucket atau
membuat bucket baru.
[ARTIFACT_PATH]: Jalur ke satu atau beberapa artefak. [ARTIFACT_PATH] bersifat
relatif terhadap direktori kerja Anda. Ini dapat berupa /workspace,
yang merupakan direktori kerja default Cloud Build atau direktori kerja
yang Anda tetapkan menggunakan kolom dir.
Perhatikan peringatan berikut saat menyimpan artefak di Cloud Storage:
Anda hanya dapat menentukan satu bucket untuk mengupload artefak dan Anda harus menjadi pemilik bucket. Anda dapat menentukan jalur direktori yang valid di bucket.
Anda dapat mengupload sebanyak mungkin artefak, tetapi Anda hanya dapat menentukan maksimal satu
ratus jalur artefak.
Jika Anda mengupload artefak ke bucket yang sudah memiliki artefak dengan nama yang sama, artefak baru akan menggantikan artefak yang ada. Anda dapat mengaktifkan
Pembuatan Versi Objek untuk bucket jika tidak ingin artefak yang lebih baru menggantikan artefak yang ada dengan nama yang sama.
Setelah build berhasil selesai, Anda dapat menemukan hasil upload dalam
file manifes JSON yang terletak di [STORAGE_LOCATION]/artifacts-$BUILD_ID.json.
File manifes JSON memiliki kolom berikut:
location: ini menentukan lokasi di Cloud Storage tempat artefak disimpan dan memiliki bentuk gs://[STORAGE_LOCATION]/[FILE_NAME]#[GENERATION_NUMBER]. Anda dapat menggunakan nomor generasi untuk mengidentifikasi versi data di bucket Cloud Storage secara unik.
file_hash: ini menentukan jenis hash dan nilai. Jenis hash
selalu 2, yang menentukan bahwa hash MD5 telah dilakukan.
Contoh artefak
Contoh berikut menunjukkan cara menggunakan kolom Artifacts dalam file konfigurasi
build. Dalam semua contoh ini, ganti [VALUES_IN_BRACKETS] dengan nilai yang sesuai.
Mengupload file dan folder
File konfigurasi build di bawah mengupload helloworld.class ke
gs://[STORAGE_LOCATION]/:
Untuk mengupload lebih dari satu artefak, tentukan jalur ke setiap artefak yang dipisahkan dengan
koma. Contoh berikut mengupload HelloWorld.java, HelloWorld.class,
dan cloudbuild.yaml ke gs://[STORAGE_LOCATION]/:
Anda juga dapat mengupload artefak ke jalur direktori yang valid di bucket. Contoh
berikut mengupload HelloWorld.java dan HelloWorld.class ke
gs://[BUCKET_NAME]/[FOLDER_NAME]:
Menggunakan karakter pengganti untuk mengupload lebih dari satu artefak
Saat mengupload beberapa artefak, Anda dapat menggunakan
karakter pengganti di paths untuk menentukan beberapa
file.
Contoh berikut menggunakan file bernama classes sebagai argumen, yang
berisi nama file .java yang akan dikompilasi. Kemudian, file .class diupload ke bucket Cloud Storage yang ditentukan:
Anda dapat menggunakan variabel penggantian untuk menentukan folder dalam bucket Cloud Storage. Jika folder yang telah Anda tentukan tidak ada, Cloud Build akan membuatnya untuk Anda.
Contoh di bawah ini mengupload artefak ke jalur Cloud Storage yang
menyertakan nama project Google Cloud tempat build dijalankan
(seperti gs://mybucket/myproject/):
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-08-18 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)."]]