Actualiser Jenkinsfile
Some checks reported errors
gg/pipeline/head This commit looks good
ff/pipeline/head Something is wrong with the build of this commit

This commit is contained in:
wkadmin 2025-10-30 14:30:50 +00:00
parent 65f8e584b5
commit 2c7546c67e

61
Jenkinsfile vendored
View File

@ -7,66 +7,63 @@ pipeline {
}
environment {
REGISTRY = 'registry.wk-archi-o24a-15m-g3.fr'
BACK_IMAGE = "${REGISTRY}/the-tip-top-backend"
APP_NAME = "the-tip-top-backend"
REGISTRY = "registry.wk-archi-o24a-15m-g3.fr"
IMAGE = "${REGISTRY}/${APP_NAME}:${BUILD_NUMBER}"
DEPLOY_PATH = "/srv/devops/the-tip-top"
}
stages {
stage('Checkout') {
steps {
git branch: 'main', url: 'https://gitea.wk-archi-o24a-15m-g3.fr/wkadmin/the-tip-top-backend.git'
echo "📦 Récupération du code source depuis Gitea..."
checkout scm
}
}
stage('Build Backend Image') {
stage('Install dependencies') {
steps {
sh '''
echo "📦 Installation des dépendances..."
npm install
echo "🐳 Construction de limage Docker backend..."
docker build -t $BACK_IMAGE:latest .
'''
echo "📦 Installation des dépendances NPM..."
sh 'npm ci'
}
}
stage('Push Image to Registry') {
stage('Build Docker image') {
steps {
withCredentials([usernamePassword(credentialsId: 'gitea-credentials', usernameVariable: 'USER', passwordVariable: 'PASS')]) {
sh '''
echo "🔑 Connexion au registre Docker Gitea..."
docker login $REGISTRY -u $USER -p $PASS
echo "🐳 Construction et tag de limage Docker..."
sh 'docker build -t ${IMAGE} .'
}
}
echo "📤 Envoi de limage vers le registre..."
docker push $BACK_IMAGE:latest
'''
stage('Push to Registry') {
steps {
echo "📤 Envoi de limage vers le registry privé..."
withCredentials([usernamePassword(credentialsId: 'registry-creds', usernameVariable: 'USER', passwordVariable: 'PASS')]) {
sh 'echo $PASS | docker login $REGISTRY -u $USER --password-stdin'
sh 'docker push $IMAGE'
}
}
}
stage('Deploy Backend on VPS') {
stage('Deploy') {
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
"
'''
}
echo "🚀 Déploiement du backend via Docker Compose..."
sh """
cd ${DEPLOY_PATH}
docker compose pull backend
docker compose up -d --no-deps --build backend
"""
}
}
}
post {
success {
echo "✅ Backend déployé avec succès !"
echo "✅ Déploiement du backend réussi !"
}
failure {
echo "❌ Échec du pipeline Backend — vérifier les logs Jenkins."
echo "❌ Échec du pipeline backend."
}
}
}