2026-02-24 08:15:10 +09:00
|
|
|
pipeline {
|
|
|
|
|
agent any
|
|
|
|
|
|
2026-02-25 11:24:41 +09:00
|
|
|
options {
|
|
|
|
|
disableConcurrentBuilds()
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-24 08:15:10 +09:00
|
|
|
environment {
|
|
|
|
|
DEPLOY_USER = 'hskwon'
|
|
|
|
|
RELEASE_ID = new Date().format('yyyyMMdd_HHmmss')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stages {
|
|
|
|
|
stage('Checkout') {
|
2026-02-24 21:00:07 +09:00
|
|
|
steps {
|
|
|
|
|
checkout scm
|
2026-02-25 12:52:18 +09:00
|
|
|
script {
|
|
|
|
|
env.GIT_COMMIT_MSG = sh(script: "git log -1 --pretty=format:'%s'", returnStdout: true).trim()
|
|
|
|
|
}
|
|
|
|
|
slackSend channel: '#product_infra', color: '#439FE0', tokenCredentialId: 'slack-token',
|
|
|
|
|
message: "🚀 *mng* 빌드 시작 (`${env.BRANCH_NAME}`)\n${env.GIT_COMMIT_MSG}\n<${env.BUILD_URL}|빌드 #${env.BUILD_NUMBER}>"
|
2026-02-24 21:00:07 +09:00
|
|
|
}
|
2026-02-24 08:15:10 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ── main → 운영서버 Production 배포 ──
|
|
|
|
|
stage('Deploy Production') {
|
|
|
|
|
when { branch 'main' }
|
|
|
|
|
steps {
|
|
|
|
|
sshagent(credentials: ['deploy-ssh-key']) {
|
|
|
|
|
sh """
|
|
|
|
|
rsync -az --delete \
|
|
|
|
|
--exclude='.git' \
|
|
|
|
|
--exclude='.env' \
|
|
|
|
|
--exclude='storage/app' \
|
|
|
|
|
--exclude='storage/logs' \
|
|
|
|
|
--exclude='storage/framework/sessions' \
|
|
|
|
|
--exclude='storage/framework/cache' \
|
|
|
|
|
--exclude='node_modules' \
|
|
|
|
|
. ${DEPLOY_USER}@211.117.60.189:/home/webservice/mng/releases/${RELEASE_ID}/
|
|
|
|
|
|
|
|
|
|
ssh ${DEPLOY_USER}@211.117.60.189 '
|
|
|
|
|
cd /home/webservice/mng/releases/${RELEASE_ID} &&
|
2026-02-26 21:45:42 +09:00
|
|
|
mkdir -p bootstrap/cache storage/framework/{views,cache/data,sessions} storage/logs &&
|
|
|
|
|
sudo chown -R www-data:webservice storage/logs &&
|
2026-02-24 08:15:10 +09:00
|
|
|
ln -sfn /home/webservice/mng/shared/.env .env &&
|
|
|
|
|
ln -sfn /home/webservice/mng/shared/storage/app storage/app &&
|
|
|
|
|
composer install --no-dev --optimize-autoloader --no-interaction &&
|
|
|
|
|
npm install --prefer-offline &&
|
|
|
|
|
npm run build &&
|
|
|
|
|
php artisan config:cache &&
|
|
|
|
|
php artisan route:cache &&
|
|
|
|
|
php artisan view:cache &&
|
|
|
|
|
php artisan migrate --force &&
|
|
|
|
|
ln -sfn /home/webservice/mng/releases/${RELEASE_ID} /home/webservice/mng/current &&
|
|
|
|
|
sudo systemctl reload php8.4-fpm &&
|
|
|
|
|
cd /home/webservice/mng/releases && ls -1dt */ | tail -n +6 | xargs rm -rf 2>/dev/null || true
|
|
|
|
|
'
|
|
|
|
|
"""
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// develop → Jenkins 관여 안함 (기존 post-update hook 유지)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
post {
|
2026-02-24 20:47:03 +09:00
|
|
|
success {
|
2026-02-24 23:53:51 +09:00
|
|
|
slackSend channel: '#product_infra', color: 'good', tokenCredentialId: 'slack-token',
|
2026-02-25 12:52:18 +09:00
|
|
|
message: "✅ *mng* 배포 성공 (`${env.BRANCH_NAME}`)\n${env.GIT_COMMIT_MSG}\n<${env.BUILD_URL}|빌드 #${env.BUILD_NUMBER}>"
|
2026-02-24 20:47:03 +09:00
|
|
|
}
|
2026-02-24 08:15:10 +09:00
|
|
|
failure {
|
2026-02-24 23:53:51 +09:00
|
|
|
slackSend channel: '#product_infra', color: 'danger', tokenCredentialId: 'slack-token',
|
2026-02-25 12:52:18 +09:00
|
|
|
message: "❌ *mng* 배포 실패 (`${env.BRANCH_NAME}`)\n${env.GIT_COMMIT_MSG}\n<${env.BUILD_URL}|빌드 #${env.BUILD_NUMBER}>"
|
2026-02-24 08:15:10 +09:00
|
|
|
script {
|
|
|
|
|
if (env.BRANCH_NAME == 'main') {
|
|
|
|
|
sshagent(credentials: ['deploy-ssh-key']) {
|
|
|
|
|
sh """
|
|
|
|
|
ssh ${DEPLOY_USER}@211.117.60.189 '
|
|
|
|
|
PREV=\$(ls -1dt /home/webservice/mng/releases/*/ | sed -n "2p" | xargs basename) &&
|
|
|
|
|
[ -n "\$PREV" ] && ln -sfn /home/webservice/mng/releases/\$PREV /home/webservice/mng/current &&
|
|
|
|
|
sudo systemctl reload php8.4-fpm
|
|
|
|
|
'
|
|
|
|
|
"""
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|