스프링부트 자동빌드 스크립트 예제

2023. 2. 2. 12:54프로그램개발/java

@ECHO OFF
SET JAVA_HOME=%CD%\build\openjdk-1.8

ECHO ================================================
ECHO = VIEW Config
ECHO ================================================
ECHO JAVA_HOME : %JAVA_HOME%
ECHO ------------------------------------------------

del *.bak /Q

if NOT EXIST .\dist (
	mkdir .\dist
)

if EXIST .\dist\prod (
	rmdir .\dist\prod /s /q
)

if NOT EXIST .\dist\prod (
	mkdir .\dist\prod
)

ECHO ================================================
ECHO = SVN Update Start!
ECHO ================================================
.\build\Subversion\bin\svn.exe update

if %errorlevel% GTR 0 (
	ECHO ================================================
	ECHO = SVN Update Fail!
	ECHO ================================================
	pause
	exit -1
)

ECHO ================================================
ECHO = Backend Build Start!
ECHO ================================================
if EXIST .\dist\prod\back (
	rmdir .\dist\prod\back /s /q
)

if NOT EXIST .\dist\prod\back (
    mkdir .\dist\prod\back
)

if EXIST .\dist\prod\back (
	del .\dist\prod\back\*.* /Q
)

if EXIST .\src\BACKEND\target\ (
    rmdir .\src\BACKEND\target\ /s /q
)

if EXIST .\src\BACKEND\src\main\resources\application.properties (
	ECHO $ Copy application.properties
	
	DEL .\src\BACKEND\src\main\resources\application.properties /q
	copy .\build\Backend\application.properties.prod .\src\BACKEND\src\main\resources\application.properties
)

cd .\src\BACKEND

call mvnw clean install

if %errorlevel% GTR 0 (
	ECHO ================================================
	ECHO = Backend:prod Build Fail!
	ECHO ================================================
	pause
	exit -2
)

copy .\target\SHE.war ..\..\dist\prod\back

if EXIST .\target\ (
    rmdir .\target /s /q
)

cd ..\..

ECHO ================================================
ECHO = Batch Build Start!
ECHO ================================================
if NOT EXIST .\dist\prod\back (
    mkdir .\dist\prod\back
)

if EXIST .\src\BATCH\target\ (
    rmdir .\src\BATCH\target\ /s /q
)

if EXIST .\src\BATCH\src\main\resources\application.properties (
	ECHO $ Copy application.properties
	
	DEL .\src\BATCH\src\main\resources\application.properties /q
	copy .\build\batch\application.properties.prod .\src\BATCH\src\main\resources\application.properties
)

cd .\src\BATCH

call mvnw clean install

if %errorlevel% GTR 0 (
	ECHO ================================================
	ECHO = Batch:prod Build Fail!
	ECHO ================================================
	pause
	exit -3
)

copy .\target\SheBatch.war ..\..\dist\prod\back

if EXIST .\target\ (
    rmdir .\target /s /q
)

cd ..\..

ECHO ================================================
ECHO = Frontend Build Start!
ECHO ================================================

cd .\src\MAIN-FRONTEND

call npm install

if %errorlevel% GTR 0 (
	ECHO ================================================
	ECHO = npm install Fail!
	ECHO ================================================
	pause
	exit -4
)

call npm run build:prod

if %errorlevel% GTR 0 (
	ECHO ================================================
	ECHO = npm run build:prod Fail!
	ECHO ================================================
	pause
	exit -5
)

if EXIST .\dist\prod\front (
	rmdir .\dist\prod\front /s /q
)



if NOT EXIST ..\..\dist\prod\front (
	mkdir ..\..\dist\prod\front
)

if NOT EXIST ..\..\dist\prod\front\ROOT (
	mkdir ..\..\dist\prod\front\ROOT
)

robocopy .\dist\ ..\..\dist\prod\front\ROOT /MIR

xcopy ..\..\build\Frontend\* ..\..\dist\prod\front\ROOT\ /E /Y

if EXIST .\dist\ (
    rmdir .\dist /s /q
)

cd ..\..

ECHO ================================================
ECHO = Release Command Copy
ECHO ================================================

copy .\build\release_all.cmd .\dist\prod\release_all.cmd
copy .\build\release_back.cmd .\dist\prod\release_back.cmd
copy .\build\release_front.cmd .\dist\prod\release_front.cmd

ECHO ================================================
ECHO = Rename Folder
ECHO ================================================
set shell_cmd1=.\build\Subversion\bin\svn.exe info --show-item last-changed-date

FOR /F "tokens=*" %%F IN ('%shell_cmd1%') DO (
SET changed-date=%%F
)
echo %changed-date%

set shell_cmd2=.\build\Subversion\bin\svn.exe info --show-item revision
 
FOR /F "tokens=*" %%F IN ('%shell_cmd2%') DO (
SET revision=%%F
)

set prod=prod_%changed-date::=%_rev%revision%

rename .\dist\prod %prod%

ECHO ================================================
ECHO = Build:prod Compleated!
ECHO ================================================

timeout /t 10
반응형