【问题标题】:How to save Cloud Build Git tool builder output to a file如何将 Cloud Build Git 工具生成器输出保存到文件
【发布时间】:2019-10-14 23:31:33
【问题描述】:

我正在使用带有 git 工具构建器的 Google Cloud Build,并尝试将 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)

另外,我尝试在不使用 bash shell 的情况下运行该步骤,但在 Cloud Build 日志中仍然看不到任何输出

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

有什么想法吗?

【问题讨论】:

    标签: git google-cloud-build


    【解决方案1】:

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

    我不知道您在提交中执行了什么,这更像是一个 git 问题而不是 Cloud Build 问题。您是否在提交时执行此操作而不更改文件,例如拉取请求或合并/变基?

    【讨论】:

      【解决方案2】:

      我想通了——我的问题是我正在访问一个私有 GitHub 存储库。我没有意识到这是问题所在,因为没有错误消息。

      我尝试按照 Google 的文档 (https://cloud.google.com/cloud-build/docs/access-private-github-repos) 使用 Cloud KMS 和 SSH 令牌来访问私有存储库。但是,我最终决定为我们的部署操作创建一个 GitHub 帐户。在该帐户中,我创建了一个个人令牌。

      然后,我将令牌添加为 Cloud Build 中的触发器变量。这使我能够克隆存储库并最终在 Cloud Build 中执行 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
      

      【讨论】:

        猜你喜欢
        • 2013-09-04
        • 2017-02-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-15
        • 1970-01-01
        • 2014-05-17
        • 1970-01-01
        相关资源
        最近更新 更多