이 페이지에서는 빌드 단계 간에 데이터를 전달하는 방법을 설명합니다. Cloud Build를 처음 사용한다면 빌드 빠른 시작 및 빌드 구성 개요를 먼저 읽어보세요.
Cloud Build는 격리된 컨테이너 환경에서 일련의 빌드 단계에 따라 태스크를 실행합니다. 각 단계가 후에는 컨테이너가 제거됩니다.
이를 통해 각 단계마다 완전히 다른 도구 및 환경을 포함할 수 있으며 기본적으로 한 단계에서 생성된 모든 데이터는 다음 단계를 오염시킬 수 없습니다. 그러나 경우에 따라 빌드의 한 단계에서 상태를 계속 유지하여 후속 단계에서 사용해야 할 수도 있습니다
이러한 경우 Cloud Build는 모든 빌드 단계에 연결할 수 있는 읽기-쓰기 파일 경로인 볼륨을 제공합니다. 볼륨은 빌드 기간 동안 콘텐츠를 유지합니다. 자체 볼륨을 정의하거나 Cloud Build가 제공하는 기본 볼륨인 /workspace를 사용할 수 있습니다. 빌드를 실행하기 전에 Cloud Build는 소스 코드를 /workspace로 추출합니다. 사용자 정의 볼륨 및 /workspace에 기록된 모든 내용은 후속 단계에서 사용할 수 있습니다.
작업공간을 사용하여 데이터 전달
빌드 단계 사이에 데이터를 전달하려면 빌드 단계에서 생성된 애셋을 /workspace에 저장하세요. 그러면 이후에 생성된 빌드 단계에서 이 애셋을 사용할 수 있습니다.
다음 빌드 구성 파일 예시에서 첫 번째 빌드 단계는 /workspace/first.txt에 'First Value' 문자열을 저장하고 /workspace/second.txt에 값 2를 저장합니다. 두 번째 빌드 단계는 /workspace/first.txt 및 /workspace/second.txt의 값을 읽고 출력합니다.
YAML
steps:-id:"StoreValues"name:ubuntuentrypoint:bashargs:--c-|# Save a value to persistent volume mount: "/workspace"echo "First Value" > /workspace/first.txt &&
# Save anotherexpr 1 + 1 > /workspace/second.txt# In the next step, everything in the environment is discarded# EXCEPT items in "/workspace"-id:"ReadValues"name:ubuntuentrypoint:bashargs:--c-|# Read from "/workspace"echo "First we saved " $(cat /workspace/first.txt) &&
echo "Then we saved " $(cat /workspace/second.txt)
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-09-04(UTC)"],[[["\u003cp\u003eCloud Build utilizes build steps in isolated containers, which are discarded after each step, meaning data doesn't carry over by default.\u003c/p\u003e\n"],["\u003cp\u003eVolumes, either the default \u003ccode\u003e/workspace\u003c/code\u003e or user-defined, enable the persistence of data between Cloud Build steps.\u003c/p\u003e\n"],["\u003cp\u003eStoring data within \u003ccode\u003e/workspace\u003c/code\u003e during a build step makes the assets accessible to subsequent steps.\u003c/p\u003e\n"],["\u003cp\u003eTo use custom volumes, define a \u003ccode\u003evolumes\u003c/code\u003e block with a \u003ccode\u003ename\u003c/code\u003e and \u003ccode\u003epath\u003c/code\u003e in both the storing and consuming build steps.\u003c/p\u003e\n"]]],[],null,["# Passing data between build steps\n\nThis page explains how to pass data between build steps. If you're new to\nCloud Build, read the [Build quickstart](/build/docs/build-push-docker-image) and\nthe [Build configuration overview](/build/docs/build-config) first.\n\nCloud Build runs your tasks as a series of **build steps**, which execute\nin isolated and containerized environments. After each step, the container is discarded.\nThis allows you to have totally different tools and environments for each step,\nand by default, any data created in one step can't contaminate the next step. But\nsometimes you may need to persist state from one step of a build to use in subsequent\nsteps.\n\nFor such cases, Cloud Build provides **volumes** , which are read-write\nfile paths that you can attach to any build step. Volumes retain their contents\nthroughout the duration of the build. You can define your own volume or use\n**/workspace**, which is the default volume that Cloud Build\nprovides for you. Before executing a build, Cloud Build extracts the\nsource code to /workspace. Anything written to user-defined\nvolumes and /workspace by any step will be available to subsequent steps.\n\nPassing data using workspaces\n-----------------------------\n\nTo pass data between build steps, store the assets produced by the build step in\n`/workspace` and these assets will be available to any subsequent build steps.\n\nIn the following example build config file, the first build step stores the\nstring \"First Value\" in `/workspace/first.txt` and the value `2` in\n`/workspace/second.txt`. The second build step reads and prints the values in\n`/workspace/first.txt` and `/workspace/second.txt`. \n\n### YAML\n\n steps:\n - id: \"Store Values\"\n name: ubuntu\n entrypoint: bash\n args:\n - -c\n - |\n # Save a value to persistent volume mount: \"/workspace\"\n echo \"First Value\" \u003e /workspace/first.txt &&\n # Save another\n expr 1 + 1 \u003e /workspace/second.txt\n # In the next step, everything in the environment is discarded\n # EXCEPT items in \"/workspace\"\n - id: \"Read Values\"\n name: ubuntu\n entrypoint: bash\n args:\n - -c\n - |\n # Read from \"/workspace\"\n echo \"First we saved \" $(cat /workspace/first.txt) &&\n echo \"Then we saved \" $(cat /workspace/second.txt)\n\n### JSON\n\n {\n \"steps\": [\n {\n \"id\": \"Store Values\",\n \"name\": \"ubuntu\",\n \"entrypoint\": \"bash\",\n \"args\": [\n \"-c\",\n \"echo \\\"First Value\\\" \u003e /workspace/first.txt &&\\nexpr 1 + 1 \u003e /workspace/second.txt\\n\"\n ]\n },\n {\n \"id\": \"Read Values\",\n \"name\": \"ubuntu\",\n \"entrypoint\": \"bash\",\n \"args\": [\n \"-c\",\n \"echo \\\"First we saved \\\" $(cat /workspace/first.txt) &&\\necho \\\"Then we saved \\\" $(cat /workspace/second.txt)\\n\"\n ]\n }\n ]\n }\n\n| **Note:** The `-c` flag in the code snippets on this page is used to execute multi-line commands. Any string you pass after `-c` is treated as a command. For more information on running bash commands with `-c`, see the [bash documentation](https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Invoking-Bash).\n\nPassing data using user-specified volumes\n-----------------------------------------\n\nInstead of using the default `/workspace` volume provided by Cloud Build,\nyou can define your own volume to persist data between build steps.\n\nTo define and use your own volume:\n\n- In the build step where you want to store the data:\n - Add a `volumes` block and set the following fields:\n - `name`: Set the value of this field to the desired volume name.\n - `path`: Set the value of this field to the file path to store your data.\n - Store the data in the file path specified in `path`.\n- In the build step where you want to consume the data:\n - Add a `volumes` block with the values for `name` and `path`.\n - Consume the data from the file path specified in `path`.\n\nIn following example build config file, the first build step defines a volume\nnamed `myvolume` and stores data in `/persistent_volume/file`. The second build\nstep prints the value stored in `/persistent_volume/file`. \n\n### YAML\n\n steps:\n - name: 'ubuntu'\n entrypoint: 'bash'\n args:\n - '-c'\n - |\n echo \"Hello, world!\" \u003e /persistent_volume/file\n volumes:\n - name: 'myvolume'\n path: '/persistent_volume'\n - name: 'ubuntu'\n entrypoint: 'bash'\n args:\n - '-c'\n - |\n cat /persistent_volume/file\n volumes:\n - name: 'myvolume'\n path: '/persistent_volume'\n\n### JSON\n\n {\n \"steps\": [\n {\n \"name\": \"ubuntu\",\n \"entrypoint\": \"bash\",\n \"args\": [\n \"-c\",\n \"echo \\\"Hello, world!\\\" \u003e /persistent_volume/file\\n\"\n ],\n \"volumes\": [\n {\n \"name\": \"myvolume\",\n \"path\": \"/persistent_volume\"\n }\n ]\n },\n {\n \"name\": \"ubuntu\",\n \"entrypoint\": \"bash\",\n \"args\": [\n \"-c\",\n \"cat /persistent_volume/file\\n\"\n ],\n \"volumes\": [\n {\n \"name\": \"myvolume\",\n \"path\": \"/persistent_volume\"\n }\n ]\n }\n ]\n }\n\nWhat's next\n-----------\n\n- Learn how to [start a build manually](/build/docs/running-builds/start-build-manually).\n- Learn how to [automate builds using triggers](/build/docs/automating-builds/create-manage-triggers).\n- Learn how to [run bash scripts](/build/docs/configuring-builds/run-bash-scripts) within build steps.\n- Learn how to [configure build step order](/build/docs/configuring-builds/configure-build-step-order)."]]