Update Jenkinsfile

This commit is contained in:
Benjamin Tan 2025-12-23 16:24:42 +00:00
parent 7604562d80
commit 83a78ce336

58
Jenkinsfile vendored
View file

@ -1,5 +1,11 @@
pipeline {
agent any
environment {
APP_PORT = 6767
PID_FILE = "${WORKSPACE}/app.pid"
}
stages {
stage('Echo Version') {
steps {
@ -24,7 +30,59 @@ pipeline {
junit(testResults: 'target/surefire-reports/TEST-*.xml', keepProperties: true, keepTestNames: true)
}
}
stage('Start App') {
steps {
sh '''
set -e
if [ -f "$PID_FILE" ]; then
kill "$(cat "$PID_FILE")" || true
rm -f "$PID_FILE"
fi
echo "Starting JAR..."
nohup java -jar target/hello-demo-*.jar \
> app.log 2>&1 &
echo $! > "$PID_FILE"
echo "App started (PID: $(cat "$PID_FILE"))"
'''
}
}
stage('Integration Test') {
steps {
sh '''
set -e
echo "Waiting for app..."
for i in {1..15}; do
if curl -fs http://localhost:$APP_PORT/hello >/dev/null; then
echo "Integration test passed"
curl -s http://localhost:$APP_PORT/hello
exit 0
fi
sleep 1
done
echo "Integration test failed"
cat app.log || true
exit 1
'''
}
}
}
post {
always {
sh '''
if [ -f "$PID_FILE" ]; then
echo "Stopping application"
kill "$(cat "$PID_FILE")" || true
rm -f "$PID_FILE"
fi
'''
}
}
tools {
maven 'M398'