From da9af9fed27462d4d96ddbe159fd8c743847e51a Mon Sep 17 00:00:00 2001 From: Spring Developer Date: Sun, 21 Dec 2025 11:06:39 +0000 Subject: [PATCH] Add Jenkinsfile for CI/CD pipeline --- Jenkinsfile | 141 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..d852237 --- /dev/null +++ b/Jenkinsfile @@ -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() + } + } +}