I want to upload a patch to Jenkins but if there is a conflict so the run will abort.
I tried using this code:
REM SETUP: Apply the patch if there is one
"C:\Program Files\TortoiseSVN\bin\svn.exe" patch %WORKSPACE%\%UPLOADED_PATCH_FILE%
IF %ERRORLEVEL% NEQ 0 GOTO ERROR_HANDLER
echo.
echo PATCH UPLOADED SUCCESSFULLY!!
GOTO QUIT
:ERROR_HANDLER
echo.
echo ERROR occurred while uploading the patch!!!
exit 1
:QUIT
REM SETUP: Delete the patch file
cd %WORKSPACE%
del /Q /F %UPLOADED_PATCH_FILE%
But the conflict don't throw any error just this message:
00:00:01.738 Summary of conflicts:
00:00:01.738 Skipped paths: 1
Anyone have an idea how to catch this message?
Thanks!
I found the solution for it:
REM SETUP: Apply the patch if there is one
#echo off
set pattern=Summary of conflicts:
FOR /F "tokens=* USEBACKQ" %%F IN (`"C:\Program Files\TortoiseSVN\bin\svn.exe" patch %WORKSPACE%\%UPLOADED_PATCH_FILE%`) DO (
if "%pattern%"=="%%F" (
#echo on
ECHO "***************************************************************************"
ECHO "***************************************************************************"
ECHO "*********ERROR: Conflict found in the patch. Try try again......***********"
ECHO "***************************************************************************"
ECHO "***************************************************************************"
EXIT 1
)
)
#echo on
Related
Playing around with my Batch script again. It was brought to my attention that my update routine was not working correctly. Iteration 1 would result in the running script being deleted and not copying the new version from a folder I had selected. Iteration 2 now deletes the old script and copies the new script but with each line of code I change I end up with the currently running script closing, and the new updated script not launching.
Here's a snippet of the Update routine:
:Options
REM I'll set the variable here to what is set elsewhere in the script.
SET VERSION=Version 1.7
CLS
ECHO.
ECHO.
ECHO %VERSION%
ECHO.
ECHO.
ECHO ==================== OPTIONS =====================
ECHO.
ECHO 1. Update Script WIP
ECHO 2. Install entire script to Statup Folder
ECHO 3. Install individual items for auto-launch
ECHO 4. Install Windows Logout feature
ECHO 5. Uninstall
ECHO 6. Change Colors
ECHO 7. Changelog
ECHO.
ECHO =======PRESS 'Q' TO QUIT OR 'B' TO GO BACK========
ECHO.
SET OPTION=
SET /P OPTION=Select an Option:
IF /I '%OPTION%'=='1' GOTO Update
IF /I '%OPTION%'=='2' GOTO Install
IF /I '%OPTION%'=='3' GOTO I_Install
IF /I '%OPTION%'=='4' GOTO I_Logout
IF /I '%OPTION%'=='5' GOTO Uinstall
IF /I '%OPTION%'=='6' GOTO Colors
IF /I '%OPTION%'=='7' GOTO Changelog
IF /I '%OPTION%'=='q' GOTO quit
IF /I '%OPTION%'=='quit' GOTO quit
IF /I '%OPTION%'=='b' GOTO menu
IF /I '%OPTION%'=='back' GOTO menu
ECHO.
ECHO ============INVALID INPUT============
ECHO Please select a number
ECHO or select 'Q' or 'B'.
ECHO ======PRESS ANY KEY TO CONTINUE======
PAUSE > NUL
GOTO Options
:Update
ECHO.
IF EXIST "%appdata%\Microsoft\Windows\Start Menu\Programs\Startup\Shortcut Browser *.bat" (
GOTO Update_1
) ELSE (
ECHO You have not installed the script yet. Please install the script first.
)
PAUSE
GOTO Options
:Update_1
IF EXIST "%userprofile%\AppData\Local\Temp\Update.bat" (
GOTO Update_2
) ELSE (
REM Here the main script writes an update script to a batch file
ECHO DEL "%appdata%\Microsoft\Windows\Start Menu\Programs\Startup\Shortcut Browser *.bat" > "%userprofile%\AppData\Local\Temp\Update.bat"
REM I replaced the original file location with one on the desktop. The original location was on a network drive, location is confidential.
ECHO COPY "%userprofile\Desktop\Shortcut Browser *.bat" "%appdata%\Microsoft\Windows\Start Menu\Programs\Startup" >> "%userprofile%\AppData\Local\Temp\Update.bat"
ECHO CALL "%appdata%\Microsoft\Windows\Start Menu\Programs\Startup\Shortcut Browser *.bat" >> "%userprofile%\AppData\Local\Temp\Update.bat"
ECHO EXIT >> "%userprofile%\AppData\Local\Temp\Update.bat"
)
GOTO Update_2
REM Here the main script calls upon the update script
:Update_2
CALL "%userprofile%\AppData\Local\Temp\Update.bat"
REM The script seems to hang here. Either both the scripts will remain open or close or a combination depending on where CALL and START were used.
PAUSE
GOTO Options
I saw elsewhere I could have used the FC command. I didn't know about it until troubleshooting this problem. I've gotten this far and I feel I'm just missing some small trick to get the new updated script to launch.
If you need any more info let me know. I think I covered everything.
#ECHO OFF
SETLOCAL
TITLE Super Script 5000
:Options
REM I'll set the variable here to what is set elsewhere in the script.
SET VERSION=Version 1.7
CLS
ECHO.
ECHO.
ECHO %VERSION%
ECHO.
ECHO.
ECHO ==================== OPTIONS =====================
ECHO.
ECHO 1. Update Script WIP
ECHO 2. Install entire script to Statup Folder
ECHO 3. Install individual items for auto-launch
ECHO 4. Install Windows Logout feature
ECHO 5. Uninstall
ECHO 6. Change Colors
ECHO 7. Changelog
ECHO.
ECHO =======PRESS 'Q' TO QUIT OR 'B' TO GO BACK========
ECHO.
SET "OPTION="
SET /P "OPTION=Select an Option: "
IF /I "%OPTION%"=="1" GOTO Update
IF /I "%OPTION%"=="2" GOTO Install
IF /I "%OPTION%"=="3" GOTO I_Install
IF /I "%OPTION%"=="4" GOTO I_Logout
IF /I "%OPTION%"=="5" GOTO Uinstall
IF /I "%OPTION%"=="6" GOTO Colors
IF /I "%OPTION%"=="7" GOTO Changelog
IF /I "%OPTION%"=="q" GOTO quit
IF /I "%OPTION%"=="quit" GOTO quit
IF /I "%OPTION%"=="b" GOTO menu
IF /I "%OPTION%"=="back" GOTO menu
ECHO.
ECHO ============INVALID INPUT============
ECHO Please select a number
ECHO or select 'Q' or 'B'.
ECHO ======PRESS ANY KEY TO CONTINUE======
PAUSE > NUL
GOTO Options
:Update
ECHO.
IF EXIST "%appdata%\Microsoft\Windows\Start Menu\Programs\Startup\Shortcut Browser *.bat" (
GOTO Update_1
) ELSE (
ECHO You have not installed the script yet. Please install the script first.
)
PAUSE
GOTO Options
:Update_1
IF EXIST "%tmp%\update.bat" (
2>NUL DEL "%tmp%\update.bat" || GOTO Options
)
SETLOCAL
FOR %%A IN (
"%appdata%\Microsoft\Windows\Start Menu\Programs\Startup\Shortcut Browser *.bat"
) DO (
SET "old_version=%%~A"
SET "old_dir=%%~dpA"
SET "old_file=%%~nxA"
)
FOR %%A IN (
"%userprofile%\Desktop\Shortcut Browser *.bat"
) DO (
SET "new_version=%%~A"
SET "new_dir=%%~dpA"
SET "new_file=%%~nxA"
)
IF NOT DEFINED old_version (
ENDLOCAL
GOTO Options
) ELSE IF NOT DEFINED new_version (
ENDLOCAL
GOTO Options
)
(
ECHO #ECHO OFF
ECHO SETLOCAL
ECHO.
ECHO ECHO Update and restarting...
ECHO ^>NUL PING localhost -n 3
ECHO.
ECHO SET "old_version=%old_version%"
ECHO SET "new_version=%new_version%"
ECHO SET "updated_version=%old_dir%\%new_file%"
ECHO.
ECHO CALL :log /clear_log
ECHO.
ECHO IF NOT EXIST "%%new_version%%" (
ECHO CALL :log ERROR: Not exist "%%new_version%%".
ECHO EXIT /B 1
ECHO ^)
ECHO.
ECHO CALL :log Move old_version to old_version.bak.
ECHO MOVE "%%old_version%%" "%%old_version%%.bak" ^|^| (
ECHO CALL :log ERROR: Move failed to backup old version.
ECHO EXIT /B 2
ECHO ^)
ECHO.
ECHO CALL :log Copy new_version to old_version.
ECHO COPY "%%new_version%%" "%%appdata%%\Microsoft\Windows\Start Menu\Programs\Startup\" ^|^| (
ECHO CALL :log ERROR: Copy failed. Restore old version.
ECHO MOVE "%%old_version%%.bak" "%%old_version%%" ^|^| (
ECHO CALL :log ERROR: Restore old version failed.
ECHO EXIT /B 3
ECHO ^)
ECHO EXIT /B 4
ECHO ^)
ECHO.
ECHO CALL :log Delete old_version.bak.
ECHO DEL "%%old_version%%.bak" ^|^| (
ECHO CALL :log WARNING: Delete backup file failed.
ECHO ^)
ECHO.
ECHO IF NOT EXIST "%%updated_version%%" (
ECHO CALL :log ERROR: Not exist: "%%updated_version%%"
ECHO EXIT /B 5
ECHO ^)
ECHO.
ECHO ENDLOCAL
ECHO.
ECHO ECHO Ready to restart updated version
ECHO PAUSE
ECHO CALL "%old_dir%\%new_file%"
ECHO EXIT /B
ECHO.
ECHO :log
ECHO SETLOCAL
ECHO SET "log=%%tmp%%\update.log"
ECHO IF /I "%%~1"=="/clear_log" TYPE NUL ^> "%%log%%" ^& EXIT /B
ECHO IF /I "%%~1"=="/delete_log" 2^>NUL DEL "%%log%%" ^& EXIT /B
ECHO SET args=%%*
ECHO IF NOT DEFINED args EXIT /B
ECHO ECHO %%*
ECHO ^>^> "%%log%%" ECHO %%*
ECHO EXIT /B
) > "%tmp%\update.bat"
ENDLOCAL
START "Super Script 5000" "cmd /c "%tmp%\update.bat""
EXIT
:Quit
Tested on a Win7 VM. The script needs to restart on update else
weird issues may occur. CMD does not like scripts changing as it
is reading and interpreting them. Even reusing the same console
using START with /B may cause key input issues.
update.bat is overwritten every update as it stores absolute paths
so each update will be different paths with the filenames changing.
Using a wildcard with CALL may not work too well otherwise.
update.bat moves the old version to a .bak file, copies the new
version and if successful, deletes the .bak file, else moves the
.bak file to the old version. This is just to ensure a current
version always exists even if the update fails.
Changed quotes in :Options label from ' to ". Quotes are not
interchangeable like some other languages. Example: "%OPTION%"
will work if contains a space though '%OPTION%' may cause error.
I notice no SETLOCAL at the top of your full script. Advise you add
it unless you have a good reason not to.
I merged labels :Update_1 and :Update_2 into one.
Perhaps adjust Ping localhost -n number if more or less time is
needed.
Look at the %tmp%\update.log if a problem happens. Though expect
the errors to show in the console as the label :log in
update.bat echoes to console and writes to the log.
If i play this batch file, it send me error message such like this,
"the system cannot find the file specified"
I searched a lot, but i do not know ...
i saw this article already, but it did not work.
System cannot find the path specified
echo off
echo **** TEST BACK UP BATCH FILE STARTS ****
setlocal enabledelayedexpansion
:LOOP
FOR %%f in (C:\Web\FTP\A\*.txt) do (
xcopy /Y %%f "C:\Web\FTP\A\B\"
SET "file=%%~nf"
SET "mydate=!date:~10,4!!date:~7,2!!date:~4,2!"
SET "mytime=!time:~0,2!!time:~3,2!!time:~6,2!"
ren "C:\Web\FTP\A\B\%file%.txt" "!file!_!mydate!!mytime!.txt"
move /Y "C:\Web\FTP\A\!file!.txt" "C:\Web\FTP\A\C\in\"
)
timeout /t 15
goto LOOP
Here are all the changes suggested in the comments above.
echo off
setlocal enabledelayedexpansion
echo **** TEST BACK UP BATCH FILE STARTS ****
:LOOP
FOR %%G in (C:\Web\FTP\A\*.txt) do (
SET "mydate=%date:~10,4%%date:~7,2%%date:~4,2%"
SET "mytime=%time:~0,2%%time:~3,2%%time:~6,2%"
xcopy /Y "%%~G" "C:\Web\FTP\A\B\%%~nG_!mydate!!mytime!.txt"
move /Y "%%~G" "C:\Web\FTP\A\C\in\"
)
timeout /t 15
goto LOOP
I'm working on the following batch script and I'm not sure how I can achieve the results I'm looking for. I searched here as well as online, but I didn't see anything that looked like what I'm looking for. Any help is appreciated.
I need to check if two files exist as well as if they don't. Currently I've got the code below working, however if one file exists or is missing it goes in a 3rd direction (I've updated the code to account for the 3rd direction so now it works fine, but I know there is much room for improvement!). I know it's not pretty, but it works and the pretty code doesn't.
Please note that there are other files in the same directory with the same extensions, so searching by extension will not work.
Working Code:
#echo off
echo checking file structure...
if exist "file1.exe" (
if exist "file2.zip" (
goto ok
)
)
if not exist "file1.exe" (
if not exist "file2.zip" (
goto download
)
)
if not exist "file1.exe" (
goto download
)
)
if not exist "file2.zip" (
goto download
)
)
:download
echo downloading missing files.
:ok
echo Install successful
What I would like to do:
(The following code isn't expected to work, it's my thoughts written out)
#echo off
set file1=setup.exe
set file2=package.zip
if exist $file1 && $file2 then goto ok
else if not exist $file1 || $file2 goto download
Example of why checking for the two files alone will not work
echo checking file structure...
if exist "setup.exe" if exist "package.zip" goto TEST1
if not exist "setup.exe" if not exist "package.zip" goto TEST2
ECHO [Error!] - 1 File is present, the other is missing!
PAUSE
:TEST1
ECHO [Success!] - Found both files, YAY!
PAUSE
:TEST2
ECHO [Error!] - No matching files found.
PAUSE
The parentheses are neccessary for the else clause.
#echo off
echo checking file structure...
if exist "file1.exe" (
if exist "file2.zip" (
goto :ok
) else goto :download
) else goto :download
:download
echo downloading missing files.
:ok
echo Install successful
But the else isn't required at all because the program flow falls through to the download label
#echo off
echo checking file structure...
if exist "file1.exe" if exist "file2.zip" goto :ok
:download
echo downloading missing files.
:ok
echo Install successful
Why perenthesize? Simply try.
#echo off
echo checking file structure...
if exist "file1.exe" if exist "file2.zip" echo Install successful
if not exist "file1.exe" echo downloading missing "file1.exe"
if not exist "file2.zip" echo downloading missing "file2.zip"
or in a loop:
#echo off
for %%i in ("file1.exe" "file2.zip") do if not exist "%%i" echo %%i Must be downloaded & goto :EOF
echo Successful Installation
:again
for %%a in ("file1.exe" "file2.zip") do if not exist "%%~a" call :download "%%~a" &goto again
And then write an internal procedure to download the missing file supplied as %1
Possibly you'd want to install a counter and report in the :download procedure if the download is being executed, and if so of which file - and count the number of iterations to stop the process if the download fails too often.
An advantage here is that there's no real limit to the number of filenames that can be included in the parentheses
Found the solution! Added some if exist parameters to account for empty folders.
for /D %%I in ("%~dp0*") do (
cd /D %%I
if exist *pm.wav (
if exist *.xml (
tar -cvzf %%~nxI.tar.gz *pm.wav *.xml
)
)
)
cd..
Download & execute
#echo off
echo checking file structure...
if exist "C:\Users\Himel\Desktop\5MB.zip" (
if exist "C:\Users\Himel\Desktop\5MB.zip" (
goto ok
)
)
if not exist "C:\Users\Himel\Desktop\5MB.zip" (
if not exist "C:\Users\Himel\Desktop\5MB.zip" (
goto download
)
)
if not exist "C:\Users\Himel\Desktop\5MB.zip" (
goto download
)
)
if not exist "C:\Users\Himel\Desktop\5MB.zip" (
goto download
)
)
:download
echo downloading missing files.
SETLOCAL
rem FOR DOWNLOADING FILES, THIS SCRIPT IS USING THE "BITSADMIN.EXE" SYSTEM FILE.
rem IT IS PRESENT ON MOST WINDOWS VERSION, PROBABLY FROM WINDOWS XP TO WINDOWS 10.
:SETUP
rem URL (5MB TEST FILE):
SET "FILE_URL=http://ipv4.download.thinkbroadband.com/5MB.zip"
rem SAVE IN CUSTOM LOCATION:
rem SET "SAVING_TO=C:\Folder\5MB.zip"
rem SAVE IN THE CURRENT DIRECTORY
SET "SAVING_TO=5MB.zip"
SET "SAVING_TO=%~dp0%SAVING_TO%"
:MAIN
ECHO.
ECHO DOWNLOAD SCRIPT EXAMPLE
ECHO.
ECHO FILE URL: "%FILE_URL%"
ECHO SAVING TO: "%SAVING_TO%"
ECHO.
rem UNCOMENT AND MODIFY THE NEXT LINE IF YOU NEED TO USE A PROXY SERVER:
rem CALL :DOWNLOAD_PROXY_ON "PROXY-SERVER.COM:8080"
rem THE MAIN DOWNLOAD COMMAND:
CALL :DOWNLOAD_FILE "%FILE_URL%" "%SAVING_TO%"
rem UNCOMMENT NEXT LINE FOR DISABLING THE PROXY (IF YOU USED IT):
rem CALL :DOWNLOAD_PROXY_OFF
:RESULT
ECHO.
IF EXIST "%SAVING_TO%" ECHO YOUR FILE HAS BEEN SUCCESSFULLY DOWNLOADED.
IF NOT EXIST "%SAVING_TO%" ECHO ERROR, YOUR FILE COULDN'T BE DOWNLOADED.
ECHO.
:EXIT_SCRIPT
PAUSE
EXIT /B
rem FUNCTIONS SECTION
:DOWNLOAD_FILE
rem BITSADMIN COMMAND FOR DOWNLOADING FILES:
bitsadmin /transfer mydownloadjob /download /priority FOREGROUND %1 %2
GOTO :EOF
:DOWNLOAD_PROXY_ON
rem FUNCTION FOR USING A PROXY SERVER:
bitsadmin /setproxysettings mydownloadjob OVERRIDE %1 "<local>"
GOTO :EOF
:DOWNLOAD_PROXY_OFF
rem FUNCTION FOR STOP USING A PROXY SERVER:
bitsadmin /setproxysettings mydownloadjob NO_PROXY
GOTO :EOF
share
:ok
echo Install successful
I have created a BAT file to uninstall any version of skype. It works fine. I am wanting to set it up to also check the event viewer to see that it uninstalled successfully. I was wondering if there was anyone that has done something to this nature. So far, this is what I have:
#echo off
echo Closing skype...
taskkill /F /IM Skype.exe
echo Removing previous versions...
wmic product where "Name like 'Skype%%'" call uninstall
New Code:
#ECHO off
IF EXSIST "C:\Program Files (x86)\Skype" GOTO INSTALLED
ELSE IF EXSIST "C:\Program Files\Skype" GOTO INSTALLED
ELSE GOTO NOTINSTALLED
:Installed
taskkill /F /IM skype.exe
wmic product where "name like 'Skype%%'" call uninstall
shutdown /r /f
:NOTINSTALLED
EXIT
You can check the %errorlevel% variable to get the last error code.
If it's 0, then it worked!
if %errorlevel%==0 echo Uninstall successful
EDIT:
An update for your new code, (you can't do an else if in batch, only use them individually)
#ECHO off
IF EXIST "C:\Program Files (x86)\Skype" GOTO INSTALLED
IF EXIST "C:\Program Files\Skype" GOTO INSTALLED
EXIT
:INSTALLED
taskkill /F /IM skype.exe
wmic product where "name like 'Skype%%'" call uninstall
shutdown /r /f
You can try:
(
echo.Exit code was %errorlevel%
echo.
echo.Uninstall application terminated on %date% - %time%
) > ".\uninstall_log.txt"
If you want to output to console then use this:
echo.
echo.
echo.Exit code was %errorlevel%
echo.
echo.Uninstall application terminated on %date% - %time%
echo.
echo.
echo.
echo.Press any key to exit Skype uninstaller.
pause>nul
exit
Will this work on Windows 8 and always work? I've tested it on Windows 7 but I'm not sure... I had a friend test it and he said that it coudn't find the correct path but I checked and the syntax of the commands is the same and I don't know why there'd be a problem. This is assuming %USERPROFILE%\Documents\My Games\Terraria\Players and %USERPROFILE%\Google Drive exists already
#echo off
echo Administrative permissions required. Detecting permissions...
net session >nul 2>&1
if %errorLevel% == 0 (
echo Success: Administrative permissions confirmed.
) else (
echo Failure: Current permissions inadequate. Please run as administatior.
pause >nul
exit
)
echo ---------------------------------------------
echo Below enter "S" for simple install type or "A" for avanced install type.
echo (Simple is recommended, only use advanced if you know what your doing!)
echo ---------------------------------------------
set /p option=Enter:
if /i "%option%"=="S" goto simple
if /i "%option%"=="A" goto advanced
echo Your entry did not match available options. Try again.
pause >nul
exit
:simple
mklink /d "%USERPROFILE%\Google Drive\Terraria" "%USERPROFILE%\Documents\My Games\Terraria\Players"
cd %USERPROFILE%\Google Drive\Terraria\
copy /y NUL marker >nul
cd %USERPROFILE%\Documents\My Games\Terraria\Players
if exist marker (
echo Validation of installation complete. Symbolic link functional.
del marker
) else (
echo SOMETHING WENT WRONG!!!!!!!!
)
echo ==============
echo You Selected Simple. & echo.If there are no errors above, your installation should be complete.
echo ==============
pause >nul
exit
:advanced
mkdir "%USERPROFILE%\Google Drive\Terraria"
mklink /d "%USERPROFILE%\Google Drive\Terraria\Players" "%USERPROFILE%\Documents\My Games\Terraria\Players"
cd %USERPROFILE%\Google Drive\Terraria\Players
copy /y NUL marker >nul
cd %USERPROFILE%\Documents\My Games\Terraria\Players
if exist marker (
echo Validation of installation complete. Symbolic link functional.
del marker >nul
) else (
echo SOMETHING WENT WRONG!!!!!!!!
)
echo ==============
echo You Selected Advanced. & echo.If there are no errors above, your installation should be complete.
echo ==============
pause >nul
exit
If delivered that all paths exist....
mklink command was introduced in Vista so the script won't work on XP/2003.