Actualiser Jenkinsfile

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

102
Jenkinsfile vendored
View File

@ -1,53 +1,67 @@
pipeline { pipeline {
agent any agent any
environment { environment {
REGISTRY = 'registry.wk-archi-o24a-15m-g3.fr' REGISTRY = 'registry.wk-archi-o24a-15m-g3.fr'
BACK_IMAGE = "${REGISTRY}/the-tip-top-backend" 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'
}
} }
stages { stage('Build Backend Image') {
stage('Checkout') { steps {
steps { sh '''
git branch: 'main', url: 'https://gitea.wk-archi-o24a-15m-g3.fr/wkadmin/the-tip-top-backend.git' echo "📦 Installation des dépendances..."
} npm install
}
stage('Build Backend') { echo "🐳 Construction de limage Docker backend..."
steps { docker build -t $BACK_IMAGE:latest .
sh ''' '''
npm ci }
npm run build || true
docker build -t $BACK_IMAGE:latest .
'''
}
}
stage('Push Image') {
steps {
sh '''
docker login $REGISTRY -u $REGISTRY_USER -p $REGISTRY_PASS
docker push $BACK_IMAGE:latest
'''
}
}
stage('Deploy Backend') {
steps {
sshagent(['vps-ssh-key']) {
sh '''
ssh debian@51.75.24.29 "
cd /srv/devops/the-tip-top &&
docker compose up -d --build backend
"
'''
}
}
}
} }
post { stage('Push Image to Registry') {
success { echo "✅ Backend déployé avec succès" } steps {
failure { echo "❌ Échec du pipeline Backend" } 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."
}
}
} }