the-tip-top-backend/Jenkinsfile
2025-10-30 13:27:50 +00:00

68 lines
1.6 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'
BACK_IMAGE = "${REGISTRY}/the-tip-top-backend"
}
stages {
stage('Checkout') {
steps {
git branch: 'main', url: 'https://gitea.wk-archi-o24a-15m-g3.fr/wkadmin/the-tip-top-backend.git'
}
}
stage('Build Backend Image') {
steps {
sh '''
echo "📦 Installation des dépendances..."
npm install
echo "🐳 Construction de limage Docker backend..."
docker build -t $BACK_IMAGE:latest .
'''
}
}
stage('Push Image to Registry') {
steps {
withCredentials([usernamePassword(credentialsId: 'gitea-registry', usernameVariable: 'USER', passwordVariable: 'PASS')]) {
sh '''
echo "🔑 Connexion au registre..."
docker login $REGISTRY -u $USER -p $PASS
echo "📤 Push de limage vers le registre..."
docker push $BACK_IMAGE:latest
'''
}
}
}
stage('Deploy Backend on VPS') {
steps {
sshagent(['vps-ssh-key']) {
sh '''
echo "🚀 Déploiement du backend sur le VPS..."
ssh -o StrictHostKeyChecking=no debian@51.75.24.29 "
cd /srv/devops/the-tip-top &&
docker compose pull backend &&
docker compose up -d --build backend
"
'''
}
}
}
}
post {
success {
echo "✅ Backend déployé avec succès !"
}
failure {
echo "❌ Échec du pipeline Backend — vérifier les logs Jenkins."
}
}
}