Search code examples
packerazure-devops-pipelineshashicorp-packer

Pipeline fails when running Packer fix


I'm trying to run Packer (1.7) in an Azure DevOps pipeline.

The pkr.hcl files passes validation on my PC running Packer 1.7.3. The pipeline runs Packer 1.7.2.

The YAML task in the pipeline reads like this:

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

When run in the pipeline it reads:

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.

The # is the first character in the .pkr.hcl file. And changing the beginning of the file will change what character shows up as invalid.

Why is it trying to run "packer fix" instead of "packer build"?


Solution

  • So it turns out that the Packer task in Azure Pipelines doesn't work with current versions of Packer.

    Run Packer as part of a script task instead.

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