Reputation: 15395
My command:
"7-set-up-default" : {
"command" : { "Fn::Join" : ["", [
"robocopy /move C:\\inetpub\\wwwroot\\ C:\\inetpub\\wwwroot\\Default\\\n",
"powershell \"Import-Module WebAdministration;",
"Set-ItemProperty 'IIS:\\Sites\\Default Web Site' -name physicalpath -value 'C:\\inetpub\\wwwroot\\Default\\'\""
]]},
"waitAfterCompletion" : "0"
},
Fails with this not-so-helpful stack trace:
Error encountered during build of config: Command 07-set-up-default failed
Traceback (most recent call last):
File "cfnbootstrap\construction.pyc", line 513, in run_config
File "cfnbootstrap\construction.pyc", line 125, in run_commands
File "cfnbootstrap\command_tool.pyc", line 113, in apply
ToolError: Command 07-set-up-default failed
2013-08-18 08:35:29,611 [ERROR] Unhandled exception during build: Command 07-set-up-default failed
Traceback (most recent call last):
File "cfn-init", line 122, in <module>
File "cfnbootstrap\construction.pyc", line 117, in build
File "cfnbootstrap\construction.pyc", line 502, in build
File "cfnbootstrap\construction.pyc", line 513, in run_config
File "cfnbootstrap\construction.pyc", line 125, in run_commands
File "cfnbootstrap\command_tool.pyc", line 113, in apply
ToolError: Command 07-set-up-default failed
However, pasting my command directly into a cmd window works fine:
robocopy /move C:\inetpub\wwwroot\ C:\inetpub\wwwroot\Default\
powershell "Import-Module WebAdministration;Set-ItemProperty 'IIS:\Sites\Default Web Site' -name physicalpath -value 'C:\inetpub\wwwroot\Default\'"
Can anyone help?
Upvotes: 0
Views: 1382
Reputation: 4309
Because robocopy doesn't use standard return codes. It doesn't actually fail, but the command line interprets its return code as a failure. See this Robocopy return code reference.
What you need to do is wrap robocopy and interpret the return values like this.
"a-sync" : {
"command" : {"Fn::Join" : ["",[
"(robocopy c:\\latest c:\\inetpub\\", {"Ref" : "Name"}, " /MIR) ^& IF %ERRORLEVEL% LEQ 4 exit /B 0"
]]},
"waitAfterCompletion" : "1"
},
This is cut and pasted from a sript that works, so you'll need to change the parameters - but the key part is to wrap the robocopy command in parenthesis, and at the ^& IF stuff at the end.
Effectively it's converting all the success return codes from robocopy into a success code recognised by the OS.
Upvotes: 1