Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing Tags into build-image.ps1 #11606

Open
2 of 15 tasks
paul-towler opened this issue Feb 15, 2025 · 2 comments
Open
2 of 15 tasks

Passing Tags into build-image.ps1 #11606

paul-towler opened this issue Feb 15, 2025 · 2 comments

Comments

@paul-towler
Copy link

Description

When passings Tags as a Hashtable into ./images.CI/linux-and-win/build-image.ps1, packer build fails

Platforms affected

  • Azure DevOps
  • GitHub Actions - Standard Runners
  • GitHub Actions - Larger Runners

Runner images affected

  • Ubuntu 20.04
  • Ubuntu 22.04
  • Ubuntu 24.04
  • macOS 13
  • macOS 13 Arm64
  • macOS 14
  • macOS 14 Arm64
  • macOS 15
  • macOS 15 Arm64
  • Windows Server 2019
  • Windows Server 2022
  • Windows Server 2025

Image version and build link

Not found

Is it regression?

No

Expected behavior

Show Packer Version
Packer v1.10.2

Your version of Packer is out of date! The latest version
is 1.11.2. You can update by downloading from www.packer.io/downloads
Download packer plugins
Validate packer template
Syntax-only check passed. Everything looks okay.
Build ubuntu-22 VM
==> azure-arm.build_image: Running builder ...

Actual behavior

Packer v1.10.2

Your version of Packer is out of date! The latest version
is 1.11.2. You can update by downloading from www.packer.io/downloads
Download packer plugins
Validate packer template
Syntax-only check passed. Everything looks okay.
Build ubuntu-22 VM

Error: Missing attribute separator

on line 1:
(source code not available)

Expected a newline or comma to mark the beginning of the next attribute.

Repro steps

  1. Pass Tags into Build VM Task in the image-generation.yml
- task: PowerShell@2
    displayName: 'Build VM'
    inputs:
      filePath: ./images.CI/linux-and-win/build-image.ps1
      arguments: |
        -ClientId $(CLIENT_ID) `
        -ClientSecret "$(CLIENT_SECRET)" `
        -TemplatePath $(TemplatePath) `
        -ImageName "$(ManagedImageName)" `
        -ImageResourceGroupName $(AZURE_RESOURCE_GROUP) `
        -TempResourceGroupName "$(TempResourceGroupName)" `
        -SubscriptionId $(AZURE_SUBSCRIPTION) `
        -TenantId $(AZURE_TENANT) `
        -Location $(AZURE_LOCATION) `
        -Tags @{Owner="MyTag"}   #<---------------- Passing Tags
      pwsh: true
    env:
      PACKER_LOG: 1
      PACKER_LOG_PATH: "$(Agent.TempDirectory)/packer-log.txt"
  1. The build-image.ps1 script converts the hashtable using:
$azure_tags = ($Tags.GetEnumerator() | ForEach-Object { "{0}={1}" -f $_.Key, $_.Value }) -join ","
  1. packer build fails with the following variable and the actual output:
-var "azure_tags={Owner=MyTag}" `

To resolve the issue:

  • Change the following command:
$azure_tags = ($Tags.GetEnumerator() | ForEach-Object { "{0}={1}" -f $_.Key, $_.Value }) -join ","`

to:

$azure_tags = $Tags | ConvertTo-Json -Compress
  • Change the following var reference for azure_tags:
-var "azure_tags={$azure_tags}" `

To

-var "azure_tags=$azure_tags" `
  • packer build succeeds with the following variable and the actual output:
-var "azure_tags={"Owner":"MyTag"}"
@Prabhatkumar59
Copy link
Contributor

Hi @paul-towler - Thank you for bringing this issue to our attention. We will look into this issue and will update you after investigating.


@Alexey-Ayupov
Copy link
Contributor

Hi @paul-towler, We also use tags for our test builds, but we didn't encounter this issue. And the reason is that our tag values ​​were "true" or "false". However, with any other values, we see the same error. Let us test your solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants