2025-12-27 08:42:52 +08:00
|
|
|
pipeline {
|
|
|
|
|
agent any
|
|
|
|
|
|
|
|
|
|
environment {
|
|
|
|
|
APP_NAME = "petclinic"
|
|
|
|
|
DOCKER_USER = "rizjosel"
|
|
|
|
|
IMAGE_TAG = "${BUILD_NUMBER}"
|
|
|
|
|
IMAGE_NAME = "${DOCKER_USER}/${APP_NAME}:${IMAGE_TAG}"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
triggers {
|
|
|
|
|
// Triggered by GitHub Pull Requests
|
|
|
|
|
githubPullRequest()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stages {
|
|
|
|
|
|
2025-12-27 09:08:40 +08:00
|
|
|
stage('Notify GitHub Pending') {
|
|
|
|
|
steps {
|
|
|
|
|
script {
|
|
|
|
|
githubNotify context: 'Jenkins CI', status: 'PENDING'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-27 08:42:52 +08:00
|
|
|
stage('List Workspace') {
|
|
|
|
|
steps {
|
|
|
|
|
sh 'ls -l'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stage('CI / Unit Tests') {
|
|
|
|
|
steps {
|
|
|
|
|
script {
|
|
|
|
|
try {
|
|
|
|
|
// Run Gradle unit tests
|
|
|
|
|
sh './gradlew clean build -x test'
|
|
|
|
|
junit 'build/test-results/test/*.xml'
|
|
|
|
|
} catch (err) {
|
|
|
|
|
error "Unit tests failed!"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stage('CI / Docker Build') {
|
|
|
|
|
steps {
|
|
|
|
|
script {
|
|
|
|
|
try {
|
|
|
|
|
sh "docker build -t ${IMAGE_NAME} ."
|
|
|
|
|
} catch (err) {
|
|
|
|
|
error "Docker build failed!"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stage('CI / Docker Integration') {
|
|
|
|
|
steps {
|
|
|
|
|
script {
|
|
|
|
|
try {
|
|
|
|
|
// Start Docker container
|
|
|
|
|
sh "docker run -d --name ${APP_NAME}-test -p 8080:8080 ${IMAGE_NAME}"
|
|
|
|
|
sh "sleep 15" // wait for app to start
|
|
|
|
|
|
|
|
|
|
// Health check
|
|
|
|
|
sh "curl -f http://localhost:8080/actuator/health"
|
|
|
|
|
} catch (err) {
|
|
|
|
|
error "Docker integration tests failed!"
|
|
|
|
|
} finally {
|
|
|
|
|
// Clean up container
|
|
|
|
|
sh "docker stop ${APP_NAME}-test || true"
|
|
|
|
|
sh "docker rm ${APP_NAME}-test || true"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-12-27 09:08:40 +08:00
|
|
|
|
|
|
|
|
post {
|
|
|
|
|
success {
|
|
|
|
|
script {
|
|
|
|
|
githubNotify context: 'Jenkins CI', status: 'SUCCESS'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
failure {
|
|
|
|
|
script {
|
|
|
|
|
githubNotify context: 'Jenkins CI', status: 'FAILURE'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-12-27 08:42:52 +08:00
|
|
|
}
|