通过使用 gsutil 从另一个文件读取路径来访问一个存储桶中的文件

Access a file in one bucket by reading the path from another file using gsutil

访问一个存储桶中文件的最佳方式是什么,该文件的路径存储在不同存储桶中的另一个文件中?

大多数多重步骤建议使用 Cloud Storage 在步骤之间持久化值并将变量值写入文件,但经过多次尝试,即使对于 Cloud Build 设置中的简单用例,我们也无法实现这一点。

我们尝试过的许多事情中的一小部分:

在 Cloud Shell 中串联步骤在 Cloud Shell 中有效,但在 Cloud Build 步骤中失败:

gsutil cp gs://bucket_1/filepath.txt filepath.txt && filepath=$(<filepath.txt) && gsutil cp gs://bucket_2/filepath local_dest.txt

Cloud Build 失败,因为它无法识别命令“filepath=$(

Cloudbuild.yaml 步(简化测试)。第一步成功,第二步失败

- name: gcr.io/cloud-builders/gsutil
  id: 'step1'
  entrypoint: 'gsutil'
  args: ['cp', 'gs://bucket_1/filepath.txt', 'filepath.txt']
  volumes:
  - name: data
    path: /persistent_volume

- name: gcr.io/cloud-builders/gsutil
  id: 'step2'
  entrypoint: 'gsutil'
  args: ['filepath=$(<filepath.txt)', 'gsutil cp gs://anc-android-builds/$BRANCH_NAME/filepath local_dest.txt']
  volumes:
  - name: data
    path: /persistent_volume

错误: CommandException:无效命令“filepath=$(

我们尝试了不同的方法来推动它,并将其分解为多个步骤,但似乎没有任何效果。

这一定是一个简单的答案,但我们似乎无法弄明白。请大家帮忙指教

为了实现您正在寻找的内容,您需要修改第二步,因为现在入口点需要一个 gsutil 命令,但不会立即收到它。因此,您需要更改为:

- name: gcr.io/cloud-builders/gsutil
  id: 'step2'
  entrypoint: 'bash'
  args:
      - '-c'
      - |
      - filepath=$(<filepath.txt) && gsutil cp gs://anc-android-builds/$BRANCH_NAME/filepath local_dest.txt
  volumes:
  - name: data
    path: /persistent_volume

您可能需要稍微调整一下,具体取决于您的具体情况,但这应该是实现您想要的目标的正确途径。