Skip to content

PowerShell provisioner silently ignores some types of errors #4916

@sandersaares

Description

@sandersaares

Packer v1.0.0 on Windows 10 Enterprise 15063.296.

Building a Windows Server 2016 Standard image on Hyper-V.

The following provisioner contains invalid PowerShell commands. I would expect the build to fail. However, these errors are silently ignored.

    {
      "type": "powershell",
      "inline": "this is not a valid powershell command"
    }

Debug log snippet:

2017/05/23 09:47:38 packer.exe: 2017/05/23 09:47:38 [DEBUG] connecting to remote shell using WinRM
2017/05/23 09:47:38 ui: ==> hyperv-iso: Connected to WinRM!
==> hyperv-iso: Connected to WinRM!
2017/05/23 09:47:38 packer.exe: 2017/05/23 09:47:38 Running the provision hook
==> hyperv-iso: Provisioning with Powershell...
2017/05/23 09:47:38 ui: ==> hyperv-iso: Provisioning with Powershell...
==> hyperv-iso: Provisioning with shell script: C:\Users\saares\AppData\Local\Temp\packer-powershell-provisioner887540923
2017/05/23 09:47:38 packer.exe: 2017/05/23 09:47:38 Found command: this is not a valid powershell command
2017/05/23 09:47:38 ui: ==> hyperv-iso: Provisioning with shell script: C:\Users\saares\AppData\Local\Temp\packer-powershell-provisioner887540923
2017/05/23 09:47:38 packer.exe: 2017/05/23 09:47:38 Opening C:\Users\saares\AppData\Local\Temp\packer-powershell-provisioner887540923 for reading
2017/05/23 09:47:38 packer.exe: 2017/05/23 09:47:38 Building command line for: if (Test-Path variable:global:ProgressPreference){$ProgressPreference='SilentlyContinue'};$env:PACKER_BUILDER_TYPE="hyperv-iso"; $env:PACKER_BUILD_NAME="hyperv-iso"; &'c:/Windows/Temp/script.ps1';exit $LastExitCode
2017/05/23 09:47:38 packer.exe: 2017/05/23 09:47:38 [INFO] 39 bytes written for 'uploadData'
2017/05/23 09:47:38 [INFO] 39 bytes written for 'uploadData'
2017/05/23 09:47:38 packer.exe: 2017/05/23 09:47:38 Uploading file to 'c:/Windows/Temp/script.ps1'
2017/05/23 09:47:38 packer.exe: 2017/05/23 09:47:38 Copying file to $env:TEMP\winrmcp-848ef57a-37f2-474c-60ab-df80537f7458.tmp
2017/05/23 09:47:38 packer.exe: 2017/05/23 09:47:38 Moving file from $env:TEMP\winrmcp-848ef57a-37f2-474c-60ab-df80537f7458.tmp to c:\Windows\Temp\script.ps1
2017/05/23 09:47:41 packer.exe: #< CLIXML
2017/05/23 09:47:41 packer.exe: <Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"><Obj S="progress" RefId="0"><TN RefId="0"><T>System.Management.Automation.PSCustomObject</T><T>System.Object</T></TN><MS><I64 N="SourceId">1</I64><PR N="Record"><AV>Preparing modules for first use.</AV><AI>0</AI><Nil /><PI>-1</PI><PC>-1</PC><T>Completed</T><SR>-1</SR><SD> </SD></PR></MS></Obj></Objs>2017/05/23 09:47:41 Removing temporary file $env:TEMP\winrmcp-848ef57a-37f2-474c-60ab-df80537f7458.tmp
2017/05/23 09:47:43 packer.exe: 2017/05/23 09:47:43 [INFO] starting remote command: powershell -executionpolicy bypass -encodedCommand aQBmACAAKABUAGUAcwB0AC0AUABhAHQAaAAgAHYAYQByAGkAYQBiAGwAZQA6AGcAbABvAGIAYQBsADoAUAByAG8AZwByAGUAcwBzAFAAcgBlAGYAZQByAGUAbgBjAGUAKQB7ACQAUAByAG8AZwByAGUAcwBzAFAAcgBlAGYAZQByAGUAbgBjAGUAPQAnAFMAaQBsAGUAbgB0AGwAeQBDAG8AbgB0AGkAbgB1AGUAJwB9ADsAJABlAG4AdgA6AFAAQQBDAEsARQBSAF8AQgBVAEkATABEAEUAUgBfAFQAWQBQAEUAPQAiAGgAeQBwAGUAcgB2AC0AaQBzAG8AIgA7ACAAJABlAG4AdgA6AFAAQQBDAEsARQBSAF8AQgBVAEkATABEAF8ATgBBAE0ARQA9ACIAaAB5AHAAZQByAHYALQBpAHMAbwAiADsAIAAmACcAYwA6AC8AVwBpAG4AZABvAHcAcwAvAFQAZQBtAHAALwBzAGMAcgBpAHAAdAAuAHAAcwAxACcAOwBlAHgAaQB0ACAAJABMAGEAcwB0AEUAeABpAHQAQwBvAGQAZQA=
2017/05/23 09:47:46 ui:     hyperv-iso: #< CLIXML
    hyperv-iso: #< CLIXML
2017/05/23 09:47:48 packer.exe: 2017/05/23 09:47:48 [INFO] command 'powershell -executionpolicy bypass -encodedCommand aQBmACAAKABUAGUAcwB0AC0AUABhAHQAaAAgAHYAYQByAGkAYQBiAGwAZQA6AGcAbABvAGIAYQBsADoAUAByAG8AZwByAGUAcwBzAFAAcgBlAGYAZQByAGUAbgBjAGUAKQB7ACQAUAByAG8AZwByAGUAcwBzAFAAcgBlAGYAZQByAGUAbgBjAGUAPQAnAFMAaQBsAGUAbgB0AGwAeQBDAG8AbgB0AGkAbgB1AGUAJwB9ADsAJABlAG4AdgA6AFAAQQBDAEsARQBSAF8AQgBVAEkATABEAEUAUgBfAFQAWQBQAEUAPQAiAGgAeQBwAGUAcgB2AC0AaQBzAG8AIgA7ACAAJABlAG4AdgA6AFAAQQBDAEsARQBSAF8AQgBVAEkATABEAF8ATgBBAE0ARQA9ACIAaAB5AHAAZQByAHYALQBpAHMAbwAiADsAIAAmACcAYwA6AC8AVwBpAG4AZABvAHcAcwAvAFQAZQBtAHAALwBzAGMAcgBpAHAAdAAuAHAAcwAxACcAOwBlAHgAaQB0ACAAJABMAGEAcwB0AEUAeABpAHQAQwBvAGQAZQA=' exited with code: 0
2017/05/23 09:47:48 packer.exe: 2017/05/23 09:47:48 [INFO] RPC endpoint: Communicator ended with: 0
2017/05/23 09:47:48 [INFO] 1082 bytes written for 'stderr'
    hyperv-iso: <Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"><Obj S="progress" RefId="0"><TN RefId="0"><T>System.Management.Automation.PSCustomObject</T><T>System.Object</T></TN><MS><I64 N="SourceId">1</I64><PR N="Record"><AV>Preparing modules for first use.</AV><AI>0</AI><Nil /><PI>-1</PI><PC>-1</PC><T>Completed</T><SR>-1</SR><SD> </SD></PR></MS></Obj><S S="Error">this : The term 'this' is not recognized as the name of a cmdlet, function, script file, or operable program. Check _x000D__x000A_</S><S S="Error">the spelling of the name, or if a path was included, verify that the path is correct and try again._x000D__x000A_</S><S S="Error">At C:\Windows\Temp\script.ps1:1 char:1_x000D__x000A_</S><S S="Error">+ this is not a valid powershell command_x000D__x000A_</S><S S="Error">+ ~~~~_x000D__x000A_</S><S S="Error">    + CategoryInfo          : ObjectNotFound: (this:String) [], CommandNotFoundException_x000D__x000A_</S><S S="Error">    + FullyQualifiedErrorId : CommandNotFoundException_x000D__x000A_</S><S S="Error"> _x000D__x000A_</S></Objs>
2017/05/23 09:47:48 [INFO] 0 bytes written for 'stdout'
2017/05/23 09:47:48 [INFO] RPC client: Communicator ended with: 0
2017/05/23 09:47:48 [INFO] RPC endpoint: Communicator ended with: 0
2017/05/23 09:47:48 packer.exe: 2017/05/23 09:47:48 [INFO] 1082 bytes written for 'stderr'
2017/05/23 09:47:48 packer.exe: 2017/05/23 09:47:48 [INFO] 0 bytes written for 'stdout'
2017/05/23 09:47:48 packer.exe: 2017/05/23 09:47:48 [INFO] RPC client: Communicator ended with: 0
2017/05/23 09:47:48 ui:     hyperv-iso: <Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"><Obj S="progress" RefId="0"><TN RefId="0"><T>System.Management.Automation.PSCustomObject</T><T>System.Object</T></TN><MS><I64 N="SourceId">1</I64><PR N="Record"><AV>Preparing modules for first use.</AV><AI>0</AI><Nil /><PI>-1</PI><PC>-1</PC><T>Completed</T><SR>-1</SR><SD> </SD></PR></MS></Obj><S S="Error">this : The term 'this' is not recognized as the name of a cmdlet, function, script file, or operable program. Check _x000D__x000A_</S><S S="Error">the spelling of the name, or if a path was included, verify that the path is correct and try again._x000D__x000A_</S><S S="Error">At C:\Windows\Temp\script.ps1:1 char:1_x000D__x000A_</S><S S="Error">+ this is not a valid powershell command_x000D__x000A_</S><S S="Error">+ ~~~~_x000D__x000A_</S><S S="Error">    + CategoryInfo          : ObjectNotFound: (this:String) [], CommandNotFoundException_x000D__x000A_</S><S S="Error">    + FullyQualifiedErrorId : CommandNotFoundException_x000D__x000A_</S><S S="Error"> _x000D__x000A_</S></Objs>

You can see some errors printed there but Packer just continues as if all was fine.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions