如何将Cloud Build Git tool builder输出保存到文件

如何将Cloud Build Git tool builder输出保存到文件,git,google-cloud-build,Git,Google Cloud Build,我正在使用Google Cloud Build和git tool builder,并试图将git diff的输出保存到一个文件中。然后在后面的步骤中,我想cat该文件。但是,文件总是空的,我怀疑git diff没有输出任何结果 - name: 'gcr.io/cloud-builders/git' entrypoint: /bin/bash args: - -c - | git diff-tree --name-only --no-commit-id -r $

我正在使用Google Cloud Build和git tool builder,并试图将git diff的输出保存到一个文件中。然后在后面的步骤中,我想
cat
该文件。但是,文件总是空的,我怀疑
git diff
没有输出任何结果

- name: 'gcr.io/cloud-builders/git'
  entrypoint: /bin/bash
  args:
    - -c
    - |
      git diff-tree --name-only --no-commit-id -r $SHORT_SHA > /workspace/files.txt
- name: 'gcr.io/cloud-builders/git'
  entrypoint: /bin/bash
  args: 
    - -c
    - |
      echo "File contents " $(cat /workspace/files.txt)
此外,我尝试在不使用bashshell的情况下运行该步骤,但在云构建日志中仍然没有看到任何输出

- name: 'gcr.io/cloud-builders/git'
  args: ['diff-tree', '--name-only', '--no-commit-id', '-r', '$SHORT_SHA']

有什么想法吗?

我执行了几个测试,输出在提交中打印更新的文件。它适用于长和短sha。您的cloudbuild命令是正确的(写入输出并读取)

我不知道您在提交中执行了什么,这与其说是云构建问题,不如说是git问题。您是否在提交时执行此操作而不更改文件,如请求拉入或合并/重新基础?

我发现了这一点——我的问题是访问了一个私有GitHub存储库。我没有意识到这是个问题,因为没有错误消息

我尝试按照Google的文档()使用云KMS和SSH令牌来访问私有回购。然而,我最终决定为我们的部署操作创建一个GitHub帐户。在这个账户中,我创建了一个个人代币

然后,我在CloudBuild中添加了令牌作为触发器变量。这使我能够克隆repo并最终在云构建内部执行git diff

这是最后一步:

steps:
- name: 'gcr.io/cloud-builders/git'
  args: ['clone', 'https://${_TOKEN_}@github.com/[username]/[repo]']
- name: 'gcr.io/cloud-builders/git'
  entrypoint: /bin/bash
  args:
    - -c
    - |
      cd [repo] &&
      git diff-tree --name-only --no-commit-id -r $SHORT_SHA > /workspace/files.txt