运行 Packer 修复程序时管道失败

问题描述

我正在尝试在 Azure DevOps 管道中运行 Packer (1.7)。

pkr.hcl 文件在我运行 Packer 1.7.3 的 PC 上通过了验证。管道运行 Packer 1.7.2。

管道中的 YAML 任务如下所示:

- task: PackerBuild@1
  inputs:
    templateType: 'custom'
    customTemplateLocation: 'ComboBoxes.pkr.hcl'
    imageUri: 'ssi-dev-comboBox'
    imageId: <full resource ID>

在管道中运行时,它会显示

Current installed packer version is 1.7.2.
Running packer fix command
/usr/local/bin/packer fix -validate=false /home/vsts/work/1/s/ComboBoxes.pkr.hcl
Error parsing template: invalid character '#' looking for beginning of value
##[error]Packer fix command Failed with error : ''. This Could happen if task does not support packer version.

# 是 .pkr.hcl 文件中的第一个字符。更改文件的开头将更改显示为无效的字符。

为什么它试图运行“packer fix”而不是“packer build”?

解决方法

事实证明,Azure Pipelines 中的 Packer 任务不适用于当前版本的 Packer。

改为将 Packer 作为脚本任务的一部分运行。

- task: PowerShell@2
  displayName: 'Packer build'
  inputs:
    targetType: 'inline'
    script: 'packer build $(build.artifactstagingdirectory)/ComboBoxes.pkr.hcl'