Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configuring Jenkins CI Job and FreeFileSync Batch Using Windows Batch Command

I have just setup Jenkins CI as my build server but I have an issue with correctly configuring FreeFileSync batch file and the command that calls the batch file used for deploying the application after building it.

call Path\deploy.ffs_batch

The build console displays success if deploy.ffs_batch execution was successful. But in the case of where the deploy.ffs_batch settings was wrong for example wrong path as destination, the build never stops and console log spinner on Hudson keeps spinning without stopping and without giving any information.

What I have tried is adding this command below the one above to the Windows batch command:

if %errorlevel% neq 0 exit %errorlevel%

But build still not happy (spinner keeps spinning).

However, when I check the log folder for FreeFileSync batch file, I see this:

[03:52:46 PM] Info: Starting comparison
[03:52:46 PM] Error: Cannot find the following folders: D:\Deploy\1\Dev You can ignore this error to consider each folder as empty. The folders then will be created automatically during synchronization.
[03:52:46 PM] Error: Synchronization stopped

I do understand the error and I can fix it. But I really do not want to always look in the log folder for answers when this occurs. So my question is how can I output the FreeFileSync error on Hudson console log and also abort the build using Windows batch command?

like image 904
Oluwafemi Avatar asked Aug 07 '15 07:08

Oluwafemi


1 Answers

I discovered that I was missing one vital step when an error occurred and that is stopping the synchronization when an error occurs to prevent hudson job build from running endlessly.

FreeFileSync Batch Job

After setting this to stop, I update my batch command to:

cd "Path\FreeFileSync\" 
FreeFileSync.exe "Path\deploy.ffs_batch"
echo.
echo.
echo ===============================================================================
echo ##### Results :
echo ===============================================================================
echo.
echo.
@echo off
for /f "delims=" %%x in ('dir "Path\logs\" /od /b') do set recent=%%x
echo.
echo ===============================================================================
if %ERRORLEVEL% == 0 goto SYNCSUCCESS
if %ERRORLEVEL% == 1 goto SYNCWARNINGS
if %ERRORLEVEL% == 2 goto SYNCERRORS
if %ERRORLEVEL% == 3 goto SYNCABORTED
goto SYNCFAIL
:SYNCFAIL
echo ##### FreeFileSync failed.
type "path\logs\%recent%"
exit 2
:SYNCSUCCESS
echo ##### FreeFileSync completed successfully!
exit 0
:SYNCWARNINGS
echo ##### FreeFileSync completed, but with warnings.
type "path\logs\%recent%"
exit 1
:SYNCERRORS
echo ##### FreeFileSync completed, but with warnings.
type "path\logs\%recent%"
exit 2
:SYNCABORTED
echo ##### FreeFileSync aborted.
type "path\logs\%recent%"
exit 3

Please note: Run minimized checkbox needs to be checked also to avoid the job from running continously. The job runs and stops when there is an error.

like image 127
Oluwafemi Avatar answered Nov 15 '22 09:11

Oluwafemi