mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-12-27 19:07:28 +00:00
Create Jenkinsfile.pr
Signed-off-by: Riz Urian <98958099+rizjosel@users.noreply.github.com>
This commit is contained in:
parent
99158070f1
commit
5b31262628
1 changed files with 71 additions and 0 deletions
71
Jenkinsfile.pr
Normal file
71
Jenkinsfile.pr
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
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 {
|
||||
|
||||
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"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue