【发布时间】:2021-06-04 08:15:43
【问题描述】:
我有一个使用 Terraform 进行部署的 GitHub Actions 工作流。
当 Terraform 完成后,我想获取 Terraform 输出并将其发送到工作流中的下一个作业,以便可以提取和使用片段。具体来说,我的 Terraform 部署了一个 Azure 函数,然后输出函数应用名称。然后用于告诉下一个作业在哪里部署函数代码。
但是,当我像这样重定向terraform output 的输出时:
- name: save tf output
run: terraform output -json > tfoutput.json
shell: bash
working-directory: terraform
然后放入作业神器中
- name: Upload output file
uses: actions/upload-artifact@v2
with:
name: terraform-output
path: terraform/tfoutput.json
内容生成文件如下所示:
[command]/home/runner/work/_temp/fb419afc-033e-4058-b5f3-c44b90cb0bd0/terraform-bin output -json
{
"functionappname": {
"sensitive": false,
"type": "string",
"value": "telemetry-function"
}
}
::debug::Terraform exited with code 0.
::debug::stdout: {%0A "functionappname": {%0A "sensitive": false,%0A "type": "string",%0A "value": "telemetry-function"%0A }%0A}%0A
::debug::stderr:
::debug::exitcode: 0
::set-output name=stdout::{%0A "functionappname": {%0A "sensitive": false,%0A "type": "string",%0A "value": "telemetry-function"%0A }%0A}%0A
::set-output name=stderr::
::set-output name=exitcode::0
当然,这意味着它绝对不是机器可读的,因为 Terraform 的 JSON 输出应该是这样的。
我还没有找到任何方法来删除所有无关的垃圾。值得注意的是,在 Azure DevOps 中,这种工作流的执行完全符合人们的预期。
我采取了将所有内容放在一项工作中的方法(以避免重定向输出和传递工件),然后使用terraform output | jq -r ... 将 terraform 的输出获取到我的 jq 语句中以提取值,它仍然 不起作用。出于某种原因,这个命令的输出看起来真的很垃圾。
不确定这是我可以解决的问题,是 terraform 操作中的错误,还是 GH Actions 中的一般错误。
另外,我在哪里提交关于 GH Actions 的错误???
【问题讨论】: