packer-community / packer-windows-plugins

A suite of Packer plugins for provisioning Windows machines
112 stars 20 forks source link

Script exited with non-zero exit status: 0 #67

Closed tom-henderson closed 7 years ago

tom-henderson commented 7 years ago

I have a PowerShell script that polls the state of the Local Configuration Manager and only proceeds when it's Idle. This block is inserted twice after the DSC config is applied to allow the machine complete the two reboots needed to complete the configuration.

{
    "type": "powershell",
    "inline": [
        "Wait-DscLocalConfigurationManagerIdle -Verbose"
    ],
    "pause_before": "10s"
}

With the above block the build fails with Build 'amazon-ebs' errored: Script exited with non-zero exit status: 1. Allowed exit codes are: [0]. I assume this is because the LCM initiates a reboot which forces my script to exit with a non-zero exit code:

==> amazon-ebs: Pausing 10s before the next provisioner...
==> amazon-ebs: Provisioning with Powershell...
==> amazon-ebs: Provisioning with shell script: /var/folders/p7/cc8w31ds6cx0ck31c_3xkj8w0000gn/T/packer-powershell-provisioner319103824
    amazon-ebs: VERBOSE: LCM State: Busy (LCM is continuing applying configuration after last reboot.)
    (...)
    amazon-ebs: VERBOSE: LCM State: Busy (LCM is continuing applying configuration after last reboot.)
==> amazon-ebs: Terminating the source AWS instance...
==> amazon-ebs: Cleaning up any extra volumes...
==> amazon-ebs: No volumes to clean up, skipping
==> amazon-ebs: Deleting temporary keypair...
Build 'amazon-ebs' errored: Script exited with non-zero exit status: 1. Allowed exit codes are: [0]

What's odd is if I add "valid_exit_codes": [1] to the above block, the build fails with Build 'amazon-ebs' errored: Script exited with non-zero exit status: 0. Allowed exit codes are: [1].

==> amazon-ebs: Pausing 10s before the next provisioner...
==> amazon-ebs: Provisioning with Powershell...
==> amazon-ebs: Provisioning with shell script: /var/folders/p7/cc8w31ds6cx0ck31c_3xkj8w0000gn/T/packer-powershell-provisioner817748964
    amazon-ebs: VERBOSE: LCM State: Busy (LCM is continuing applying configuration after last reboot.)
    (...)
    amazon-ebs: VERBOSE: LCM State: Busy (LCM is continuing applying configuration after last reboot.)
==> amazon-ebs: Terminating the source AWS instance...
==> amazon-ebs: Cleaning up any extra volumes...
==> amazon-ebs: No volumes to clean up, skipping
==> amazon-ebs: Deleting temporary keypair...
Build 'amazon-ebs' errored: Script exited with non-zero exit status: 0. Allowed exit codes are: [1]

The only way I can get the build to succeed is to use "valid_exit_codes": [0, 1].

Is this a bug?

mefellows commented 7 years ago

Looks like it :)

It's been a while since I've been in this space, but I do recall working on exit codes - it wasn't pretty!

I'd stick with your solution for now until we can set aside time to look at this. FWIW are you using these plugins or packer itself (they have been merged into Packer now, this issue may well be fixed there).