the-tip-top-backend/Jenkinsfile

73 lines
1.9 KiB
Groovy
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

pipeline {
agent any
environment {
REGISTRY = "registry.wk-archi-o24a-15m-g3.fr"
IMAGE_NAME = "the-tip-top-backend"
}
stages {
stage('Checkout') {
steps {
echo "📦 Récupération du code source..."
checkout scm
}
}
stage('Build Docker image') {
steps {
echo "🐳 Construction de limage Docker backend..."
sh """
docker build -t ${REGISTRY}/${IMAGE_NAME}:${BUILD_NUMBER} .
docker tag ${REGISTRY}/${IMAGE_NAME}:${BUILD_NUMBER} ${REGISTRY}/${IMAGE_NAME}:latest
"""
}
}
stage('Push to Registry') {
steps {
echo "📤 Envoi de limage vers le registre privé..."
withCredentials([usernamePassword(credentialsId: 'registry-credentials', usernameVariable: 'REG_USER', passwordVariable: 'REG_PASS')]) {
sh """
echo $REG_PASS | docker login ${REGISTRY} -u $REG_USER --password-stdin
docker push ${REGISTRY}/${IMAGE_NAME}:${BUILD_NUMBER}
docker push ${REGISTRY}/${IMAGE_NAME}:latest
"""
}
}
}
stage('Deploy') {
steps {
echo "🚀 Déploiement du backend..."
sh """
docker compose pull backend
docker compose up -d --force-recreate backend
"""
}
}
stage('Health Check') {
steps {
echo "🩺 Vérification du déploiement..."
script {
def code = sh(script: "curl -s -o /dev/null -w '%{http_code}' https://api.dsp5-archi-o24a-15m-g3.fr || echo 000", returnStdout: true).trim()
if (code != "200") {
error "Le backend ne répond pas correctement (code HTTP ${code})"
}
}
}
}
}
post {
success {
echo "✅ Déploiement du backend réussi."
}
failure {
echo "❌ Échec du pipeline backend."
}
}
}