spring-petclinic/JenkinsFile
2025-11-17 20:00:10 +00:00

87 lines
2.6 KiB
Text

pipeline {
agent any
tools {
jdk 'jdk-17'
maven 'maven-3.9.9'
}
environment {
JAVA_HOME = '/Users/mac/Library/Java/JavaVirtualMachines/ms-17.0.16/Contents/Home'
PATH = "${JAVA_HOME}/bin:${env.PATH}"
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('.') {
sh '''
echo "JAVA_HOME=$JAVA_HOME"
java -version
./mvnw -B -U clean verify -Dspring-javaformat.skip
'''
}
}
post {
always {
junit allowEmptyResults: true, testResults: 'target/surefire-reports/*.xml'
archiveArtifacts artifacts: 'target/*.jar', fingerprint: true
}
}
}
stage('SonarQube Analysis') {
steps {
dir('.') { // <-- use root directory
withCredentials([string(credentialsId: '01', variable: 'SONAR_TOKEN')]) {
sh """./mvnw 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} || true
docker -H ${DOCKER_HOST} rm ${IMAGE} || true
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" }
}
}