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