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?
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.
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.
Related
I'm trying to set up Windows Task Scheduler to run the upload_xml.cmd script below:
Inside this script I call several other files that have FTP commands, but when I run the task scheduler I configured, it only runs until step 2. How can I solve this problem?
:Step 1
Echo step 1 - Check for xml files to process
Netsh advfirewall set allprofiles state off
Of xmls.list /f/q
Dir /s/b C:\xml\UPLOAD\*.xml xmls.list
Find /c ".xml xmls.list
If% errorlevel% equ 1 goto Exit
Echo step 1 - Files found
: Step2
Echo step 2 - run the ftp script to check if the connection exists
In10xml_connect /f/q
Ftp -s: download_connect.ftpget xx.xxx.xxx.xx
If not exist in10xml_connect goto Exit
Echo step 2 - SUCCESSFUL CONNECTION
: Step3
Echo step 3 - run the ftp script to check if you can send the files
In10xml_loader.lock /f/q
Ftp -s: download_lock.ftpget xx.xxx.xxx.xx
If exist in10xml_loader.lock goto Exit
Echo step 3 - UPLOAD CAN CONTINUE
I am trying to run batch script from jenkins job which has two msiexec commands one for uninstallation and other for installation.
This script is on github so jenkins job clone the repo and then run the script
Jenkins job start execution of second msiexec (installation) command but it ends immediately.If i open Job console i can see message "Process leaked file descriptors." and job status : Success
If i run The same script through cmd without jenkins it is working fine.
setlocal enabledelayedexpansion
IF EXIST "directory path" (
msiexec /uninstall {Product ID} /qb
)
pushd \\shared drive
IF EXIST "directory path" (
msiexec /i "path to exefile" /qb
popd
exit 0
)
ELSE (
ECHO Setup Not Found in current
exit 0
)
The keyword ELSE must be on same line as ) of TRUE branch of IF condition separated from ) by a space character. The ELSE on a separate line is interpreted like name of a console application to run.
if exist "directory path" (
%SystemRoot%\System32\msiexec.exe /uninstall {Product ID} /qb
)
pushd "\\ComputerName\ShareName\"
if exist "directory path" (
%SystemRoot%\System32\msiexec.exe /i "path to exefile" /qb
) else (
echo Setup not found in %CD%.
)
popd
exit /B 0
Hint: For debugging a batch file run it from within a command prompt window and not with double clicking on it after removing or commenting all lines containing echo off. And don't use EXIT without /B as this results always in exiting entire command process and not only in exiting just processing of current batch file. Debugging a batch file in a command prompt window becomes difficult if the batch file contains EXIT without /B and this command is really executed on running the batch file because error messages output during running the batch file can't be seen in this case.
I work in IT help-desk, new to coding but put together this batch file to get our nightly updates completed faster:
#echo off
echo.
echo RTC Customer Care - Variety Pre-Eigen Updater
echo (Continue along with 'ENTER' to reach desired update.)
echo.
pause
echo.
echo ====================================
echo Transfer Required Files to C: Drive?
echo ====================================
echo.
echo.
pause
cd /d h:\smsback
call vwiw3net2.bat
echo.
echo (Finished copying files)
echo Note: If transfer failed, re-run updater.
pause
echo.
echo ===========================
echo Execute Part 1/2 of Update?
echo ===========================
echo.
echo.
pause
echo (Follow prompts till completion)
start /d "c:\smsback\1_win3_1" WindowsInstaller-KB893803-v2-x86.exe
pause
echo.
echo ===========================
echo Execute Part 2/2 of Update?
echo ===========================
echo.
echo.
pause
echo (Follow prompts till completion)
echo Note: 2nd update takes a few minutes to display.
start /d "c:\smsback\2_net2" NetFx20SP2_x86.exe
pause
echo.
echo.
echo ==================================================
echo ATTENTION: Register will RESTART to finish update.
echo ==================================================
echo.
pause
shutdown.exe /r /t 05
(goto) 2>nul & del "%~f0"
What would be some good conditional arguments for verifying that an update installed? File size? Just don't want to have to run the script to get to update 2 and open/close out of previous steps.
First, opening a command prompt window and running there start /? or help start results in getting help displayed for this command. It can be read on output help about /Dpath and other options of this command. There is no space between /D and path.
Second, start interprets first double quoted string as title. Therefore "" or "useful title" should be specified on command line with start as first parameter if any other parameter is enclosed in double quotes.
Third, if start is used to install from within a batch file, it is better to use this command with parameter /wait as it is not possible to run multiple installations parallel. msiexec used to install each security update does not allow running more than one install/repair/uninstall operation at the same time.
Fourth, most executables of Windows security updates are console applications and can be run from within a batch file without the need to use command start at all. So instead of
start /d "c:\smsback\1_win3_1" WindowsInstaller-KB893803-v2-x86.exe
it would be better to use just:
C:\smsback\1_win3_1\WindowsInstaller-KB893803-v2-x86.exe
Fifth, the executables of Windows security updates all exit with a value greater 0 on an error and with 0 on success. Therefore after running a security update executable without command start as written above a line like the following could be used to check return value of the executable.
if errorlevel 1 echo Failed to install KB893803-v2-x86, error code %ERRORLEVEL%.
See Windows Installer Error Messages and MsiExec.exe and InstMsi.exe Error Messages.
And finally which updates are installed already can be queried from Windows registry key HKEY_LOCAL_MACHINE\Software\Microsoft\Updates and its subkeys.
In MS-DOS (Windows 2003 R2 Server), I have a batchfile which has the FTP command in it, eg:-
FTP.CMD
-------
cd d:\extracts\scripts
ftp -i -s:ftp_getfile.ftp
exit
I would like the batch file to raise and return an error level 1 for failure instead of 0,
so that the calling batchfile can deal with it.
The error could be caused by the FTP server being down. Right now, nothing is returned to indicate
an error condition occured.
Please can someone advise?
Thanks! :)
Maybe too late, but it is possible. I'm running the following script to check for errors in the text that's returned by the FTP script. If you know the error text that's returned by FTP, then that's what you look for with the 'find' command.
The ftp commands are in a file called ftp.inp, just check out the help of FTP on how to use '-s'.
ftp -s:ftp.inp > ftp.log
find /I /C "not connected" ftp.log
IF NOT ERRORLEVEL 1 GOTO FTPERROR
find /I /C "not found" ftp.log
IF NOT ERRORLEVEL 1 GOTO FTPERROR
find /I /C "failed" ftp.log
IF NOT ERRORLEVEL 1 GOTO FTPERROR
REM --- no errors found
GOTO :END
:FTPERROR
REM --- error found
:END
As per this question:
How to capture the ftp error code in batch scripts?
The windows FTP command doesn't support this behaviour (or PASV mode) and is basically next to useless.
You might want to try NcFtp instead. It's free, small, portable, and has decent error codes.
I'm trying to get our build scripts (which use MSBuild) working correctly on Vista and am finding that projects that have the Register Output (in linker options) option set to True fail to build from the command line with something like this:
Project : error PRJ0050: Failed to register output. Please try enabling Per-user Redirection or register the component from a command prompt with elevated permissions.
Although I can easily fix this for a single machine, by running as admin or whatever I want the build script to "just work" for any dev machine.
Even to just fail the registration but have the build continue would be satisfactory. Any suggestions?
Brad
You could create cmd-file that will be contain the following text:
#echo off
call regsvr32.exe /s %1
if %errorlevel% EQU 0 goto ok
echo Fail to register %1
goto exit
:ok
echo Register successful %1
:exit
After that you should switch off registering output and one should add Custom Build Step with command <pathtocmdscript> $(TargetPath). Output one should set to $(TargetPath) for Custom Build Step.
Finally you'll got message about registering progress, but compilation will not stop on that step.