Actualiser Jenkinsfile

This commit is contained in:
wkadmin 2025-10-30 13:27:50 +00:00
parent 720b307d7e
commit b033dfabf7

32
Jenkinsfile vendored
View File

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