Update Jenkinsfile-bk
This commit is contained in:
parent
83a78ce336
commit
d5e6138439
1 changed files with 0 additions and 0 deletions
90
Jenkinsfile-bk
Normal file
90
Jenkinsfile-bk
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
pipeline {
|
||||
agent any
|
||||
|
||||
environment {
|
||||
APP_PORT = 6767
|
||||
PID_FILE = "${WORKSPACE}/app.pid"
|
||||
}
|
||||
|
||||
stages {
|
||||
stage('Echo Version') {
|
||||
steps {
|
||||
sh 'echo Print Maven Version'
|
||||
sh 'mvn -version '
|
||||
}
|
||||
}
|
||||
|
||||
stage('Build') {
|
||||
steps {
|
||||
sh 'mvn clean package -DskipTests=true'
|
||||
archiveArtifacts 'target/hello-demo-*.jar'
|
||||
}
|
||||
}
|
||||
|
||||
stage('Unit Test') {
|
||||
steps {
|
||||
script {
|
||||
sh "mvn test"
|
||||
}
|
||||
|
||||
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'
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue