initial commit

This commit is contained in:
gong01
2026-03-06 02:52:51 +08:00
commit 85278ca36f
365 changed files with 83942 additions and 0 deletions

90
jenkinsfile Normal file
View File

@@ -0,0 +1,90 @@
pipeline {
agent any
environment {
JAVA_HOME = '/var/lib/jenkins/tools/openjdk17'
MAVEN_HOME = '/usr/share/maven'
PATH = "${MAVEN_HOME}/bin:${JAVA_HOME}/bin:${PATH}"
APP_NAME = 'oms'
VERSION = '0.0.1-SNAPSHOT'
JAR_FILE = "target/oms.jar"
AWS_SERVER = '54.179.159.145'
AWS_USER = 'root'
DEPLOY_PATH = '/home/build' // 빌드 산출물 업로드 경로
RUN_PATH = '/home/run' // 실행 경로
}
stages {
stage('Checkout') {
steps {
checkout scm
}
}
stage('Build') {
steps {
sh 'echo "Building application..."'
script {
def mvnHome = tool 'maven'
sh "${mvnHome}/bin/mvn clean package -Pdev -DskipTests -Dspring.profiles.active=dev"
}
}
}
stage('Archive Artifacts') {
steps {
sh 'echo "Checking JAR file..."'
sh 'ls -la target/'
sh 'ls -la target/*.jar'
archiveArtifacts artifacts: 'target/*.jar', fingerprint: true
}
}
stage('Deploy to AWS') {
steps {
script {
// 실제 빌드된 JAR 파일 찾기
def jarFiles = sh(
script: 'find target -name "*.jar" -not -name "*-sources.jar" -not -name "*-javadoc.jar" | head -1',
returnStdout: true
).trim()
if (!jarFiles) {
error "JAR 파일을 찾을 수 없습니다."
}
def actualJarFile = jarFiles.split('\n')[0]
echo "실제 JAR 파일: ${actualJarFile}"
withCredentials([sshUserPrivateKey(credentialsId: 'coreserver', keyFileVariable: 'SSH_KEY')]) {
sh """
echo "Deploying to AWS server..."
chmod +x deploy-aws.sh
./deploy-aws.sh ${AWS_SERVER} ${AWS_USER} "\${SSH_KEY}" ${actualJarFile} ${DEPLOY_PATH}
echo "Uploading and running runApi.sh..."
chmod +x runApi.sh
scp -i "\${SSH_KEY}" runApi.sh ${AWS_USER}@${AWS_SERVER}:${RUN_PATH}/runApi.sh
ssh -i "\${SSH_KEY}" ${AWS_USER}@${AWS_SERVER} "chmod +x ${RUN_PATH}/runApi.sh && JAR_NAME=\$(basename ${actualJarFile}) BUILD_DIR=${DEPLOY_PATH} RUN_DIR=${RUN_PATH} ${RUN_PATH}/runApi.sh"
"""
}
}
}
}
}
post {
success {
echo 'Pipeline succeeded!'
// 슬랙 알림 등 추가 가능
}
failure {
echo 'Pipeline failed!'
// 실패 알림 등 추가 가능
}
always {
// 빌드 결과 정리
sh 'echo "Build completed"'
}
}
}