mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2026-01-08 11:21:11 +00:00
78 lines
2.2 KiB
Text
78 lines
2.2 KiB
Text
pipeline {
|
|
agent any
|
|
|
|
tools {
|
|
jdk 'jdk-17'
|
|
maven 'maven-3.9.9'
|
|
}
|
|
|
|
environment {
|
|
SONAR_TOKEN = credentials('01')
|
|
SONAR_HOST = 'https://sonarcloud.io'
|
|
IMAGE = 'spring-petclinic'
|
|
TAG = 'latest'
|
|
DOCKER_HOST = "tcp://10.52.81.17:2375"
|
|
}
|
|
|
|
stages {
|
|
|
|
stage('Checkout') {
|
|
steps {
|
|
git branch: 'main', url: 'https://github.com/RhitaKhadijaAssia/spring-petclinic'
|
|
}
|
|
}
|
|
|
|
stage('Build & Unit Tests') {
|
|
steps {
|
|
dir('backend') {
|
|
sh 'mvn -B -U clean verify'
|
|
}
|
|
}
|
|
post {
|
|
always {
|
|
junit allowEmptyResults: true, testResults: 'backend/target/surefire-reports/*.xml'
|
|
archiveArtifacts artifacts: 'backend/target/*.jar', fingerprint: true
|
|
}
|
|
}
|
|
}
|
|
|
|
stage('SonarQube Analysis') {
|
|
steps {
|
|
dir('backend') {
|
|
sh """
|
|
mvn sonar:sonar ^
|
|
-Dsonar.projectKey=RhitaKhadijaAssia_spring-petclinic ^
|
|
-Dsonar.organization=rhitakhadijaassia ^
|
|
-Dsonar.host.url=%SONAR_HOST% ^
|
|
-Dsonar.login=%SONAR_TOKEN%
|
|
"""
|
|
}
|
|
}
|
|
}
|
|
|
|
stage('Build Docker on remote machine') {
|
|
steps {
|
|
dir('backend') {
|
|
sh """
|
|
docker -H %DOCKER_HOST% build -t %IMAGE%:%TAG% .
|
|
"""
|
|
}
|
|
}
|
|
}
|
|
|
|
stage('Run Docker on remote machine') {
|
|
steps {
|
|
sh """
|
|
docker -H %DOCKER_HOST% stop %IMAGE% || exit 0
|
|
docker -H %DOCKER_HOST% rm %IMAGE% || exit 0
|
|
docker -H %DOCKER_HOST% run -d -p 8080:8080 --name %IMAGE% %IMAGE%:%TAG%
|
|
"""
|
|
}
|
|
}
|
|
}
|
|
|
|
post {
|
|
success { echo "Pipeline OK → Docker lancé sur la machine distante" }
|
|
failure { echo "Pipeline KO" }
|
|
}
|
|
}
|