Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
149 changes: 35 additions & 114 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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'
Expand All @@ -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}
Expand All @@ -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"

Expand Down Expand Up @@ -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 \
Expand All @@ -179,24 +101,25 @@ 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,
healthScaleFactor: 1.0

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
Expand All @@ -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: """<p>Build SUCCEEDED for project <b>${env.JOB_NAME}</b>, build number <b>#${env.BUILD_NUMBER}</b>.</p>
<p>Access the build at: <a href="${env.BUILD_URL}">${env.BUILD_URL}</a></p>
<p>Build summary and test reports are available as archived artifacts.</p>
<p>Summary file: ${env.BUILD_SUMMARY_FILE}</p>""",
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: """<p>Build is UNSTABLE for project <b>${env.JOB_NAME}</b>, build number <b>#${env.BUILD_NUMBER}</b>. This often indicates test failures.</p>
<p>Please review the test results: <a href="${env.BUILD_URL}testReport">${env.BUILD_URL}testReport</a></p>
<p>Full build log: <a href="${env.BUILD_URL}">${env.BUILD_URL}</a></p>
<p>Summary file: ${env.BUILD_SUMMARY_FILE}</p>""",
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: """<p>Build FAILED for project <b>${env.JOB_NAME}</b>, build number <b>#${env.BUILD_NUMBER}</b>.</p>
<p>Please check the console output immediately for failure reasons: <a href="${env.BUILD_URL}">${env.BUILD_URL}</a></p>
<p>Summary file (if generated before failure): ${env.BUILD_SUMMARY_FILE}</p>""",
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
1 change: 0 additions & 1 deletion StudentManager/src/student/StudentManagerTest3.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}