SPMS_WEB/Jenkinsfile
2025-12-03 14:24:07 +09:00

77 lines
2.5 KiB
Groovy

def TARGET_FRONT_BUILD = ''
def TARGET_RUN_SERVER = ''
def CONTAINER_SRC_PATH = '/src'
pipeline {
agent any
stages {
stage('Check Branch & Setup') {
steps {
script {
def branchName = env.BRANCH_NAME
echo "Current Branch: ${branchName}"
if (branchName == 'develop') {
// develop 브랜치 -> Debug 컨테이너
TARGET_FRONT_BUILD = 'spms-front-build-debug'
TARGET_RUN_SERVER = 'spms-run-debug'
echo "[DEV Mode] Target: DEBUG Container"
}
else if (branchName == 'main') {
TARGET_FRONT_BUILD = 'spms-front-build-release'
TARGET_RUN_SERVER = 'spms-run-release'
echo ">>> [PROD Mode] Target: RELEASE Container"
}
else {
error "This branch(${branchName}) can't set container (USE develop or main branch)"
}
}
}
}
stage('Checkout') {
steps {
cleanWs()
checkout scm
echo "Git Checkout Complete"
}
}
// [3단계] 컨테이너로 소스 복사
stage('Copy to Container') {
steps {
script {
def sourcePath = "${WORKSPACE}/react/."
echo "Copying from ${sourcePath} to ${TARGET_FRONT_BUILD}"
def containerId = sh(script: "docker ps -aqf 'name=${TARGET_FRONT_BUILD}'", returnStdout: true).trim()
if (containerId) {
sh "docker cp ${sourcePath} ${TARGET_FRONT_BUILD}:${CONTAINER_SRC_PATH}"
} else {
error "Container ${TARGET_FRONT_BUILD} not found!"
}
}
}
}
stage('Build Frontend') {
steps {
script {
echo "Starting React Build..."
sh "docker start -a ${TARGET_FRONT_BUILD}"
echo "React Build Complete."
}
}
}
stage('Apply & Restart') {
steps {
script {
echo "Restarting Backend Server (${TARGET_RUN_SERVER})..."
sh "docker restart ${TARGET_RUN_SERVER}"
}
}
}
}
}