Skip to content

Packer powershell provisioner sometimes fails to execute it's scripts on windows host; "Processing -File ''filename.ps1'' failed: The given path's format is not supported" #13502

@alba02119451

Description

@alba02119451

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Overview of the Issue

We are provisioning Windows vm templates using Packer and Ansible on vSphere. We run Packer in a container (alpine-based) in our gitlab CI/CD pipeline. One of the steps in this process behaves inconsistently; a script that we run using the Powershell provisioner which checks whether our other scripts have succeeded. It works most of the time, but fails for unknown reasons some of the time.

Reproduction Steps

This is the tricky part. As stated, it is an inconsistent issue that crops up in ~10% of our pipelines. When we run the exact same job again (so the same code and environment), it usually magically works all of a sudden. I would love to do some troubleshooting, but I will likely need some help with that as I have no clue where to start looking given the inconsistency of this issue.

Packer version

1.14.1

Simplified Packer Template

Packer source
source "vsphere-iso" "Windows" {
  # Vcenter configuration
  username                    = var.vcenter_username
  password                    = var.vcenter_password
  vcenter_server              = var.vcenter_server
  datacenter                  = var.datacenter
  datastore                   = var.datastore
  cluster                     = var.cluster
  folder                      = var.folder
  firmware                    = var.firmware
  vm_name                     = local.vm_name
  resource_pool               = var.resource_pool
  iso_paths                   = [
    #D-Drive
    var.iso_path_vsphere,
    #E-Drive
    var.vmware_tools
  ]
  convert_to_template         = false

  # Communicator settings
  communicator                = "ssh"
  ssh_username                = var.ssh_user
  ssh_private_key_file        = "${var.ci_project_dir}/${var.ssh_privkey}"

  # Image configuration
  guest_os_type               = var.guest_os_type
  CPUs                        = var.numvcpus
  RAM                         = var.memsize
  RAM_reserve_all             = true
  network_adapters {
    network_card = var.network_card
    network      = var.network_name
  }
  storage {
    disk_size                 = var.disk_size
    disk_thin_provisioned     = true
  }
  disk_controller_type = var.disk_controller_type

  # Boot configuration
  ##cd_content is used to load the user data onto a virtual CDROM
  floppy_content = {
    "setup/autounattend.xml" = local.autounattend
  }

  #F-Drive
  cd_files = [
    "scripts/",
    "${var.ci_project_dir}/ca-certificates/"
  ]

  cdrom_type = "sata"
  
  ## The boot command then loads the virtual CDROM into the boot process
  boot_command                = var.boot_command
  boot_wait                   = var.boot_wait
  shutdown_command            = var.shutdown_command
}

build {
  sources = ["source.vsphere-iso.Windows"]

  provisioner "powershell" {
    script = "post-build-scripts/check_scripts_outcome.ps1"
    execute_command = "powershell -ExecutionPolicy Bypass -File '{{ .Path }}' -Directory 'C:\\Windows\\Setup\\Scripts'"
  }
### There are other provisioners but they are unlikely to be useful here
}

We deliver several scripts to enable SSH, install VMware tools etc. as these are all necessary to let Packer and Ansible do their work. The step that fails is a script that checks the output of these scripts to see if any have failed. However, the issue seems to me to be with Packer, given that it complains of not finding a script named with random letters and numbers.

Operating system and Environment details

The Windows versions are Windows 11 and Windows Server 2022. Packer version is 1.14.1. We run packer from our gitlab CI/CD pipeline using a container built from the official Docker image (so alpine-based "host").

Log Fragments and crash.log files

Sometimes, this job fails:

==> vsphere-iso.Windows: Running local shell script: /tmp/packer-shell3516734848
==> vsphere-iso.Windows: Provisioning with Powershell...
==> vsphere-iso.Windows: Provisioning with powershell script: post-build-scripts/check_scripts_outcome.ps1
==> vsphere-iso.Windows: Processing -File ''c:/Windows/Temp/script-68f8c678-ecb1-3848-cc9a-0ea20a365bc6.ps1'' failed: The given path's format is not supported. Specify a valid path for the -File parameter.
==> vsphere-iso.Windows: Windows PowerShell
==> vsphere-iso.Windows: Copyright (C) Microsoft Corporation. All rights reserved.
==> vsphere-iso.Windows:
==> vsphere-iso.Windows: Install the latest PowerShell for new features and improvements! https://aka.ms/PSWindows
==> vsphere-iso.Windows:
==> vsphere-iso.Windows: Provisioning step had errors: Running the cleanup provisioner, if present...
==> vsphere-iso.Windows: Clearing boot order...
==> vsphere-iso.Windows: Powering off virtual machine...
==> vsphere-iso.Windows: Deleting floppy image...
==> vsphere-iso.Windows: Destroying VM...
==> vsphere-iso.Windows: Removing [IFS_ISA_PP01] packer_cache/packer3339943028.iso...
==> vsphere-iso.Windows: Closing sessions ....
Build 'vsphere-iso.Windows' errored after 7 minutes 23 seconds: Script exited with non-zero exit status: 4294770688. Allowed exit codes are: [0]
==> Wait completed after 7 minutes 23 seconds
==> Some builds didn't complete successfully and had errors:
--> vsphere-iso.Windows: Script exited with non-zero exit status: 4294770688. Allowed exit codes are: [0]
==> Builds finished but no artifacts were created.

Other times, it works just fine:

==> vsphere-iso.Windows: Provisioning with Powershell...
==> vsphere-iso.Windows: Provisioning with powershell script: post-build-scripts/check_scripts_outcome.ps1
==> vsphere-iso.Windows: All .err files are empty.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions