Hi Alvaro,

I was able to figure out the issue. It seems PACKER works fine.

Issue was in my script in highlighted line

WORNG:
packer build -only=BUILDER-TEST-ESXI -var-file=%VARIABLES_FILE_PATH1% 
%VARIABLES_FILE_PATH2% >> test.log  2>&1

CORRECT:
packer build -only=BUILDER-TEST-ESXI -var-file=%VARIABLES_FILE_PATH1% 
%VARIABLES_FILE_PATH2% >> test.log


Here is the working script in which i am able to catch the error...

@echo off
REM setlocal EnableDelayedExpansion
cls
SET "APP_HOME_DIR=%~dp0"
SET "APP_BIN_DIR=%~dp0bin"
SET "PACKER_HOME=;%APP_BIN_DIR%\packer"
SET "VARIABLES_FILE_PATH1=%APP_HOME_DIR%template\variablesTest.json"
SET "VARIABLES_FILE_PATH2=%APP_HOME_DIR%template\connectToESXiTest.json"
SET "PATH=%PATH%%PACKER_HOME%"

echo Validating Template
packer validate -var-file=%VARIABLES_FILE_PATH1% %VARIABLES_FILE_PATH2%

echo Packer Build
packer build -only=BUILDER-TEST-ESXI -var-file=%VARIABLES_FILE_PATH1% 
%VARIABLES_FILE_PATH2% >> test.log
IF %ERRORLEVEL% NEQ 0 echo Error: Seems packers exited with non-zero exit 
code

Thanks,
Becky

On Friday, April 14, 2017 at 2:17:55 PM UTC+5:30, Alvaro Miranda Aguilera 
wrote:
>
> Hello i see test.sh but you mention run.bat, so I assume you run packer in 
> windows, and want to capture the error?
>
>
> lets go on stages
>
> Can you run the packer in debug mode so we can confirm the exit code of 
> that part is fine?
>
> set PACKER_LOG=1
>
> then run the build
>
> share a gist (gist.github.com)
>
> and if you can run in your run.bat something like this after the packer 
> run: 
> if %errorlevel% neq 0 exit /b %errorlevel%
>
> Should help.
>
> Thanks
> Alvaro
>
> On Thu, Apr 13, 2017 at 9:49 AM, Becky <[email protected] <javascript:>> 
> wrote:
>
>> Hi, 
>>
>>
>> I am using packer 1.0.0 on Windows 10.
>>
>>  
>>
>> *Run.bat*
>>
>>  
>>
>> Packer build –only mybuilder –var-file=variables_file.json 
>>
>> Echo %errorlevel%  
>>
>> <<This always show 0 even if my shell scripts exited with returned code 
>> 1. 
>>
>> Is this expected behavior, if so then how can one catch the errors of 
>> SHELL and take action in run.bat file ?>>
>>
>>  
>>
>> *variables_file.json*
>>
>>  
>>
>> {
>>
>>     "builders": [{
>>
>>         "type": "null",
>>
>>         "name": " mybuilder",
>>
>>         "ssh_host": "{{user ` host`}}",
>>
>>         "ssh_username": "{{user ` username`}}",
>>
>>         "ssh_password": "{{user ` password`}}",
>>
>>         "ssh_timeout" : "{{user `esxi_ssh_timeout`}}"
>>
>>     }],
>>
>>     "provisioners": [{
>>
>>         "type": "shell",
>>
>>         "only": ["mybuilder"],
>>
>>         "scripts": [
>>
>>             "script/testESXi.sh"
>>
>>         ]
>>
>>     }
>>
>>     ]
>>
>> }
>>
>>  
>>
>> *testESXi.sh*
>>
>>  
>>
>> #!/bin/sh
>>
>>  
>>
>> exit 1;
>>
>>
>> Regards,
>>
>> Becky
>>
>> -- 
>> This mailing list is governed under the HashiCorp Community Guidelines - 
>> https://www.hashicorp.com/community-guidelines.html. Behavior in 
>> violation of those guidelines may result in your removal from this mailing 
>> list.
>>  
>> GitHub Issues: https://github.com/mitchellh/packer/issues
>> IRC: #packer-tool on Freenode
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "Packer" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/packer-tool/82f04172-898b-4dd3-8184-f0202aa9bf36%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/packer-tool/82f04172-898b-4dd3-8184-f0202aa9bf36%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
> Alvaro
>
>

-- 
This mailing list is governed under the HashiCorp Community Guidelines - 
https://www.hashicorp.com/community-guidelines.html. Behavior in violation of 
those guidelines may result in your removal from this mailing list.

GitHub Issues: https://github.com/mitchellh/packer/issues
IRC: #packer-tool on Freenode
--- 
You received this message because you are subscribed to the Google Groups 
"Packer" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/packer-tool/20500617-eede-4163-b7ac-d11cdec1c5af%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to