Add Jenkinsfile for CI/CD pipeline

This commit is contained in:
Spring Developer
2025-12-21 11:06:39 +00:00
parent a71279d4ba
commit da9af9fed2

141
Jenkinsfile vendored Normal file
View File

@@ -0,0 +1,141 @@
pipeline {
agent any
tools {
// Gradle은 프로젝트에 포함된 gradlew 사용
}
environment {
PROJECT_NAME = 'springboot-api'
GRADLE_OPTS = '-Dorg.gradle.daemon=false'
JAVA_HOME = '/usr/lib/jvm/java-17-openjdk-amd64'
}
stages {
stage('Checkout') {
steps {
echo '==== Checking out code from Gitea ===='
checkout scm
sh 'ls -lah'
}
}
stage('Gradle Wrapper Permissions') {
steps {
echo '==== Setting Gradle wrapper permissions ===='
dir('springboot-api') {
sh 'chmod +x gradlew'
}
}
}
stage('Build Info') {
steps {
echo '==== Environment Information ===='
dir('springboot-api') {
sh '''
java -version
./gradlew --version
'''
}
}
}
stage('Clean') {
steps {
echo '==== Cleaning previous builds ===='
dir('springboot-api') {
sh './gradlew clean'
}
}
}
stage('Compile') {
steps {
echo '==== Compiling source code ===='
dir('springboot-api') {
sh './gradlew compileJava'
}
}
}
stage('Test') {
steps {
echo '==== Running unit tests ===='
dir('springboot-api') {
sh './gradlew test --no-daemon || true'
}
}
post {
always {
// 테스트 결과 보고서 저장
junit '**/build/test-results/test/*.xml'
}
}
}
stage('Build') {
steps {
echo '==== Building Spring Boot application ===='
dir('springboot-api') {
sh './gradlew build -x test --no-daemon'
}
}
}
stage('Archive Artifacts') {
steps {
echo '==== Archiving JAR file ===='
dir('springboot-api') {
archiveArtifacts artifacts: 'build/libs/*.jar', fingerprint: true
sh 'ls -lh build/libs/'
}
}
}
stage('Docker Build') {
when {
branch 'master' // master 브랜치에서만 Docker 이미지 빌드
}
steps {
echo '==== Building Docker image ===='
dir('springboot-api') {
script {
def jarFile = sh(
script: 'ls build/libs/*.jar | head -1',
returnStdout: true
).trim()
echo "JAR file: ${jarFile}"
// Docker 이미지 빌드 (선택사항)
// sh "docker build -t springboot-api:${BUILD_NUMBER} ."
}
}
}
}
stage('Deploy Info') {
steps {
echo '==== Build completed successfully ===='
echo "Project: ${PROJECT_NAME}"
echo "Build Number: ${BUILD_NUMBER}"
echo "JAR file is ready for deployment"
}
}
}
post {
success {
echo '✅ Pipeline completed successfully!'
// 추가: 슬랙 알림, 이메일 등
}
failure {
echo '❌ Pipeline failed!'
// 추가: 실패 알림
}
always {
echo '==== Cleaning up workspace ===='
cleanWs()
}
}
}