diff --git a/Jenkinsfile b/Jenkinsfile index 304659b..ff1e7e4 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -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'