@echo off
setlocal enabledelayedexpansion
:: UTF-8 μΈμ½λ© μ€μ
chcp 65001
:: μμ
λλ ν 리λ₯Ό νλ‘μ νΈ ν΄λλ‘ λ³κ²½
cd /d D:\Projects\MyProject
:: λ‘κ·Έ νμΌ κ²½λ‘ μ€μ
set LOGFILE=%USERPROFILE%\Desktop\myproject_build.log
:: λ‘κ·Έ νμΌμ νμ¬ λ μ§ λ° μκ° κΈ°λ‘
echo.>> "%LOGFILE%"
echo ========================= >> "%LOGFILE%"
echo %date% %time% >> "%LOGFILE%"
echo ========================= >> "%LOGFILE%"
:: SVN μ
λ°μ΄νΈ μ€ν λ° λ‘κ·Έ νμΌμ κΈ°λ‘
echo Running SVN update... >> "%LOGFILE%"
svn update >> "%LOGFILE%" 2>&1
:: Maven λΉλ μ€ν λ° λ‘κ·Έ νμΌμ κΈ°λ‘ (ν
μ€νΈ μλ΅)
echo Running Maven build... >> "%LOGFILE%"
mvn clean package -DskipTests -Dfile.encoding=UTF-8 -e -fae >> "%LOGFILE%" 2>&1
:: λΉλ μ±κ³΅ μ¬λΆ νμΈ ν μ΄λ²€νΈ λ‘κ·Έμ κΈ°λ‘
if %ERRORLEVEL% equ 0 (
echo Build completed successfully. >> "%LOGFILE%"
powershell -Command "Write-EventLog -LogName Application -Source 'MyProject Maven Build & Deploy' -EventId 100 -EntryType Information -Message 'Build completed successfully.'" >> "%LOGFILE%" 2>&1
) else (
echo Build failed. >> "%LOGFILE%"
powershell -Command "Write-EventLog -LogName Application -Source 'MyProject Maven Build & Deploy' -EventId 101 -EntryType Error -Message 'Build failed.'" >> "%LOGFILE%" 2>&1
)
echo Build process finished. >> "%LOGFILE%"
λΆμ
@echo off
λ°°μΉ νμΌ μ€ν μ λͺ λ Ήμ΄λ₯Ό νλ©΄μ μΆλ ₯νμ§ μλλ‘ μ€μ
setlocal enabledelayedexpansion
λ³μ κ°μ μ€μκ°μΌλ‘ μ λ°μ΄νΈν μ μλλ‘ μ§μ°λ νμ₯μ νμ±ν
chcp 65001
UTF-8 μΈμ½λ©μ μ¬μ©νμ¬ λ‘κ·Έ νμΌμ΄λ μ½μμμ νκΈμ΄ κΉ¨μ§μ§ μλλ‘ μ€μ
cd /d D:\Projects\MyProject
μμ λλ ν 리λ₯Ό D:\Projects\MyProjectλ‘ λ³κ²½
set LOGFILE=%USERPROFILE%\Desktop\myproject_build.log
λ‘κ·Έ νμΌμ μ¬μ©μ λ°ννλ©΄μ μμ±νλλ‘ μ€μ
echo.>> "%LOGFILE%"
echo ========================= >> "%LOGFILE%"
echo %date% %time% >> "%LOGFILE%"
echo ========================= >> "%LOGFILE%"
λΉλ λ‘κ·Έμ κ°λμ±μ λμ΄κΈ° μν΄ ν€λ μΆκ°
=========================
2025-03-28 12:34:56.78
=========================
μ΄λ° μμΌλ‘ μΆκ°λλ€.
svn update >> "%LOGFILE%" 2>&1
SVN μ μ₯μμμ μ΅μ μ½λ μ λ°μ΄νΈνκ³ λ‘κ·Έ νμΌμ κΈ°λ‘
2>&1 : νμ€ μλ¬ μΆλ ₯(2λ²)μ νμ€ μΆλ ₯(1λ²)μΌλ‘ ν©μΉλ€λ λ―
mvn clean package -DskipTests -Dfile.encoding=UTF-8 -e -fae >> "%LOGFILE%" 2>&1
Mavenμ μ¬μ©νμ¬ νλ‘μ νΈλ₯Ό λΉλνλ©°, ν μ€νΈλ μλ΅ (-DskipTests)
ν μ€νΈ μλ΅ : μκ°μ΄ λ§μ΄ κ±Έλ €μ λΉλλ§ νκΈ°λ νκ³ , λ€λ₯Έ κ³³μμ ν μ€νΈλ₯Ό μ€ννκ³ μλ€λ©΄ κ΅³μ΄ νμ μλ€κ³ νλ¨νμ¬ μΆκ°λμ΄μλ κ².
-e : μλ¬κ° λ°μνλ©΄ μμΈν λ‘κ·Έ μΆλ ₯
-fae : μλ¬ λ°μ μμλ κ°λ₯ν ν κ³μ μ§ν
if %ERRORLEVEL% equ 0 (...) else (...)
%ERRORLEVEL% κ°μ΄ 0μ΄λ©΄ λΉλ μ±κ³΅, 0μ΄ μλλ©΄ μ€ν¨λ‘ νλ¨.
λ§μ§λ§ λͺ λ Ήμ΄λ 'mvn clean package'μΈλ° μ±κ³΅νλ©΄ 0, μ€ν¨νλ©΄ λ€λ₯Έ κ°μΌλ‘ λ°νλ¨.
1 : μΌλ°μ μΈ μ€λ₯(μ: νμΌ μμ, μ€ν μ€ν¨)
2 : μλͺ»λ λͺ λ Ήμ΄ μΈμ
100 : Maven λΉλ μ€ν¨ (μΌλ°μ μΌλ‘ 100)
101 : νΉμ ν μ€λ₯ μν©(μ: λ€νΈμν¬ μ€λ₯)
powershell -Command "Write-EventLog -LogName Application -Source 'MyProject Maven Build & Deploy' -EventId 100 -EntryType Information -Message 'Build completed successfully.'" >> "%LOGFILE%" 2>&1
μ±κ³΅ μ : μλμ° μ΄λ²€νΈ λ‘κ·Έ(Application λ‘κ·Έ)μ λΉλ μ±κ³΅ κΈ°λ‘
powershell -Command "Write-EventLog -LogName Application -Source 'MyProject Maven Build & Deploy' -EventId 101 -EntryType Error -Message 'Build failed.'" >> "%LOGFILE%" 2>&1
μ€ν¨ μ : μ΄λ²€νΈ λ‘κ·Έμ λΉλ μ€ν¨ λ©μμ§ κΈ°λ‘
echo Build process finished. >> "%LOGFILE%"
μ 체 λΉλ νλ‘μΈμ€κ° μλ£λμμμ λ‘κ·Έ νμΌμ κΈ°λ‘
enabledelayedxpansion μ¬μ©νλ μ΄μ
setlocal enabledelayedexpansion
λ°°μΉ νμΌμμ κΈ°λ³Έμ μΌλ‘ λ³μ(%λ³μλͺ %)μ ν λ² κ°μ΄ μ€μ λλ©΄ κ·Έ μ€μ΄ μ€νλ λκΉμ§λ§ μ μ§λ¨.
νμ§λ§ μ λͺ λ Ήμ΄λ₯Ό μ¬μ©νλ©΄ !λ³μλͺ ! νμμΌλ‘ λ³μλ₯Ό μ€μκ° μ λ°μ΄νΈ κ°λ₯
κΈ°λ³Έμ μΈ λ³μ μ¬μ©
@echo off
set count=0
for /L %%i in (1,1,5) do (
set /a count+=1
echo count = %count% :: μ¬κΈ°μ νμ 0μΌλ‘ μΆλ ₯λ¨
)
κ²°κ³Ό
count = 0
count = 0
count = 0
count = 0
count = 0
!λ³μ!λ₯Ό μ¬μ©ν μ€μκ° μ λ°μ΄νΈ
@echo off
setlocal enabledelayedexpansion
set count=0
for /L %%i in (1,1,5) do (
set /a count+=1
echo count = !count! :: 1λΆν° 5κΉμ§ μ¦κ°νλ©° μΆλ ₯λ¨
)
κ²°κ³Ό
count = 1
count = 2
count = 3
count = 4
count = 5