如何将 terraform 计划写入 azure devops 管道摘要中的选项卡?

问题描述 投票:0回答:1

一些 Terraform 扩展(例如 this)提供了将 Terraform 计划发布到管道运行概述/摘要中的选项卡的功能。

Microsoft DevLabs 发布的

Terraform 任务目前不支持此功能。

我正在尝试使用管道日志记录命令uploadsummary作为解决方法。但它会将输入文件读取为 Markdown。因此输出的格式在选项卡中看起来很难看。计划输出中的

#
将被视为Markdown中的标题1。
+
将被视为列表...等的项目符号。

如何修复此问题以在管道摘要中获得更清晰的 Terraform 计划选项卡?

azure-devops terraform task pipeline show
1个回答
0
投票

我找到了解决方法。

此代码片段可以在管道中使用以实现相同的目的。

  # NOTE: Some lines in the output were missing while using this task.
  # Write terraform show output in default format to a markdown file
  - task: TerraformTaskV4@4
    name: TerraformShow
    displayName: Terraform Show
    inputs:
      provider: 'azurerm'
      environmentServiceNameAzureRM: $(sctfbackend)
      command: 'show'
      commandOptions: 'tfplan -no-color'
      outputTo: 'file'
      outputFormat: 'default'
      fileName: '$(working_dir)/TerraformPlan.md'
      workingDirectory: $(working_dir)

  # Display plan in the pipeline build summary
  - task: Bash@3
    displayName: Show plan summary
    inputs:
      targetType: 'inline'
      workingDirectory: '$(working_dir)'
      script: |
        ls -la
        sed -i '1 i\```' TerraformPlan.md
        echo '```' >> TerraformPlan.md
        echo "##vso[task.uploadsummary]$(working_dir)/TerraformPlan.md"

第一步是使用

-out
获取计划文件。然后出示计划 使用标志
-no-color
以避免输出中出现着色字符。

将其写入 Markdown 文件。

将该文件的内容包含在 Markdown 的代码块中将提供更清晰的格式。

然后将文件发布到管道摘要。

© www.soinside.com 2019 - 2024. All rights reserved.