diff --git a/Jenkinsfile b/Jenkinsfile index fe2767c..ace8ee9 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,78 +1,4 @@ -<<<<<<< HEAD -pipeline { - agent any - - environment { - JUNIT_JAR_URL = 'https://repo1.maven.org/maven2/org/junit/platform/junit-platform-console-standalone/1.7.1/junit-platform-console-standalone-1.7.1.jar' - JUNIT_JAR_PATH = 'lib/junit.jar' - CLASS_DIR = 'classes' - REPORT_DIR = 'test-reports' - } - - stages { - stage('Checkout') { - steps { - checkout scm - } - } - - stage('Prepare') { - steps { - sh ''' - mkdir -p ${CLASS_DIR} - mkdir -p ${REPORT_DIR} - mkdir -p lib - echo "[+] Downloading JUnit JAR..." - curl -L -o ${JUNIT_JAR_PATH} ${JUNIT_JAR_URL} - ''' - } - } - - stage('Build') { - steps { - sh ''' - echo "[+] Compiling source files..." - cd Test2 - find src -name "*.java" > sources.txt - javac -encoding UTF-8 -d ../${CLASS_DIR} -cp ../${JUNIT_JAR_PATH} @sources.txt - ''' - } - } - - stage('Test') { - steps { - sh ''' - echo "[+] Running tests with JUnit..." - java -jar ${JUNIT_JAR_PATH} \ - --class-path ${CLASS_DIR} \ - --scan-class-path \ - --details=tree \ - --details-theme=ascii \ - --reports-dir ${REPORT_DIR} \ - --config=junit.platform.output.capture.stdout=true \ - --config=junit.platform.reporting.open.xml.enabled=true \ - > ${REPORT_DIR}/test-output.txt - ''' - } - } - } - - post { - always { - echo "[*] Archiving test results..." - junit "${REPORT_DIR}/**/*.xml" - archiveArtifacts artifacts: "${REPORT_DIR}/**/*", allowEmptyArchive: true - } - - failure { - echo "Build or test failed!" - } - - success { - echo "Build and test succeeded!" -======= -// Jenkinsfile (Declarative Pipeline) - +//작동하는 젠킨스 파일 pipeline { agent any @@ -81,7 +7,6 @@ pipeline { JUNIT_JAR_FILENAME = 'junit-platform-console-standalone.jar' JUNIT_JAR_PATH = "lib/${JUNIT_JAR_FILENAME}" // Relative to workspace root - // Source root now includes the 'StudentManager' project directory PROJECT_DIR = 'StudentManager' // The directory created by git clone if repo name is StudentManager SRC_ROOT = "${PROJECT_DIR}/src" PACKAGE_PATH = 'student' @@ -104,7 +29,6 @@ pipeline { steps { sh ''' echo "[+] Cleaning up previous build artifacts if any..." - # These paths are relative to the workspace root rm -rf ${CLASS_DIR} ${REPORT_DIR} lib echo "[+] Creating required directories..." mkdir -p ${CLASS_DIR} @@ -126,7 +50,6 @@ pipeline { steps { sh ''' echo "[+] Compiling main and test source files..." - # Paths are relative to the workspace root MAIN_JAVA_FILE="${SRC_ROOT}/${PACKAGE_PATH}/StudentManager.java" TEST_FILES_PATTERN="${SRC_ROOT}/${PACKAGE_PATH}/StudentManagerTest*.java" @@ -163,7 +86,6 @@ pipeline { steps { sh ''' echo "[+] Running tests using JUnit Platform Console..." - # CLASS_DIR, JUNIT_JAR_PATH, REPORT_DIR are relative to workspace root java -jar ${JUNIT_JAR_PATH} \ --class-path ${CLASS_DIR} \ --scan-class-path \ @@ -179,15 +101,17 @@ pipeline { if [ ${TEST_EXIT_CODE} -ne 0 ] && [ ${TEST_EXIT_CODE} -ne 1 ]; then echo "[!!!] ERROR: JUnit Platform Console Runner encountered a critical error." + # Consider exiting with an error: exit 1 fi + # The junit step below will handle test failures (exit code 1) correctly. echo "[+] Tests executed. Raw console output in ${REPORT_DIR}/junit-console-output.txt" ''' } } - } + } // Closes stages - post { - always { + post { // Opens post + always { // Opens always echo "[*] Archiving test reports and build summary..." junit testResults: "${REPORT_DIR}/TEST-*.xml", allowEmptyResults: true, @@ -195,8 +119,7 @@ pipeline { archiveArtifacts artifacts: "${REPORT_DIR}/**/*", allowEmptyArchive: true - script { - // Using env.GIT_COMMIT as a workaround for scm.GIT_COMMIT script security + script { // Opens script def gitCommit = env.GIT_COMMIT ?: 'N/A (env.GIT_COMMIT not set)' def summary = """ Jenkins Build Summary @@ -213,66 +136,64 @@ pipeline { """ writeFile file: env.BUILD_SUMMARY_FILE, text: summary archiveArtifacts artifacts: env.BUILD_SUMMARY_FILE, allowEmptyArchive: true - } + } // Closes script echo "[*] Pipeline finished. Final status: ${currentBuild.currentResult}" - } + } // Closes always - success { + success { // Opens success echo "[***] PIPELINE SUCCEEDED [***]" - script { - // Assumes Email Extension Plugin is installed. - try { + script { // Opens script + try { // Opens try emailext ( subject: "SUCCESS: Jenkins Build #${env.BUILD_NUMBER} for ${env.JOB_NAME}", body: """
Build SUCCEEDED for project ${env.JOB_NAME}, build number #${env.BUILD_NUMBER}.
Access the build at: ${env.BUILD_URL}
Build summary and test reports are available as archived artifacts.
Summary file: ${env.BUILD_SUMMARY_FILE}
""", - to: 'ekdnlt714714@gmail.com', // <<< --- !!! CHANGE THIS EMAIL ADDRESS !!! + to: 'ekdnlt714714@gmail.com, songbaro@g.hongik.ac.kr, cba7215@g.hongik.ac.kr, leek0729@naver.com', mimeType: 'text/html' ) - } catch (e) { + } catch (e) { // Opens catch echo "[w] Failed to send success email. Email Extension Plugin configured correctly? Error: ${e.getMessage()}" - } - } - } + } // Closes catch + } // Closes script + } // Closes success - unstable { + unstable { // Opens unstable. This is typically when tests fail. echo "[!!!] PIPELINE UNSTABLE (Likely Test Failures) [!!!]" - script { - try { + script { // Opens script + try { // Opens try emailext ( subject: "UNSTABLE: Jenkins Build #${env.BUILD_NUMBER} for ${env.JOB_NAME} (Test Failures?)", body: """Build is UNSTABLE for project ${env.JOB_NAME}, build number #${env.BUILD_NUMBER}. This often indicates test failures.
Please review the test results: ${env.BUILD_URL}testReport
Full build log: ${env.BUILD_URL}
Summary file: ${env.BUILD_SUMMARY_FILE}
""", - to: 'ekdnlt714714@gmail.com', // <<< --- !!! CHANGE THIS EMAIL ADDRESS !!! + to: 'ekdnlt714714@gmail.com, songbaro@g.hongik.ac.kr, cba7215@g.hongik.ac.kr, leek0729@naver.com', mimeType: 'text/html' ) - } catch (e) { + } catch (e) { // Opens catch echo "[w] Failed to send unstable build email. Email Extension Plugin configured correctly? Error: ${e.getMessage()}" - } - } - } + } // Closes catch + } // Closes script + } // Closes unstable - failure { + failure { // Opens failure. This is for compile errors or other script failures. echo "[!!!] PIPELINE FAILED [!!!]" - script { - try { + script { // Opens script + try { // Opens try emailext ( subject: "FAILURE: Jenkins Build #${env.BUILD_NUMBER} for ${env.JOB_NAME}", body: """Build FAILED for project ${env.JOB_NAME}, build number #${env.BUILD_NUMBER}.
Please check the console output immediately for failure reasons: ${env.BUILD_URL}
Summary file (if generated before failure): ${env.BUILD_SUMMARY_FILE}
""", - to: 'ekdnlt714714@gmail.com', // <<< --- !!! CHANGE THIS EMAIL ADDRESS !!! + to: 'ekdnlt714714@gmail.com, songbaro@g.hongik.ac.kr, cba7215@g.hongik.ac.kr, leek0729@naver.com', mimeType: 'text/html' ) - } catch (e) { + } catch (e) { // Opens catch echo "[w] Failed to send failure email. Email Extension Plugin configured correctly? Error: ${e.getMessage()}" - } - } ->>>>>>> branch 'master' of https://github.com/ekdnlt714714/swenginnering.git - } - } -} + } // Closes catch + } // Closes script + } // Closes failure + } // Closes post +} // Closes pipeline diff --git a/StudentManager/src/student/StudentManagerTest3.java b/StudentManager/src/student/StudentManagerTest3.java index b9344eb..232a720 100644 --- a/StudentManager/src/student/StudentManagerTest3.java +++ b/StudentManager/src/student/StudentManagerTest3.java @@ -17,6 +17,5 @@ void testAddStudentDuplicate() { studentManager.addStudent("송재원"); assertThrows(IllegalArgumentException.class, () -> {studentManager.addStudent("송재원");}, "예외 발생"); System.out.println("송재원: 2025/05/28/13:53"); - System.out.println("송재원 Pull Request"); } } \ No newline at end of file