Frontend fixes: - Add eslint-config-next package to devDependencies - Update Jenkinsfile to block deployments on failed lint/tests - Add proper error handling for quality checks This ensures that the deployment only proceeds when all quality checks pass successfully, preventing broken code from being deployed. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
171 lines
5.6 KiB
Groovy
171 lines
5.6 KiB
Groovy
pipeline {
|
||
agent any
|
||
|
||
// Déclenchement automatique sur push Git
|
||
triggers {
|
||
// Vérifie les changements toutes les minutes (polling SCM)
|
||
pollSCM('* * * * *')
|
||
|
||
// Ou utiliser un webhook Gitea (recommandé)
|
||
// Le webhook doit être configuré dans Gitea pour pointer vers:
|
||
// http://jenkins-url/gitea-webhook/post
|
||
GenericTrigger(
|
||
genericVariables: [
|
||
[key: 'ref', value: '$.ref']
|
||
],
|
||
causeString: 'Triggered by Gitea push',
|
||
token: 'the-tip-top-frontend-token',
|
||
printContributedVariables: true,
|
||
printPostContent: true
|
||
)
|
||
}
|
||
|
||
parameters {
|
||
choice(
|
||
name: 'ENV',
|
||
choices: ['dev', 'preprod', 'prod'],
|
||
description: 'Choisir l'environnement de déploiement'
|
||
)
|
||
}
|
||
|
||
environment {
|
||
REGISTRY_URL = "registry.wk-archi-o24a-15m-g3.fr"
|
||
IMAGE_NAME = "the-tip-top-frontend"
|
||
}
|
||
|
||
stages {
|
||
|
||
stage('Init') {
|
||
steps {
|
||
script {
|
||
def currentBranch = sh(script: "git rev-parse --abbrev-ref HEAD", returnStdout: true).trim()
|
||
echo "🧭 Branche détectée : ${currentBranch}"
|
||
|
||
if (["dev", "preprod", "main"].contains(currentBranch)) {
|
||
env.ENV = (currentBranch == "main") ? "prod" : currentBranch
|
||
} else {
|
||
env.ENV = params.ENV ?: "dev"
|
||
}
|
||
|
||
env.TAG = "${env.ENV}-latest"
|
||
env.DEPLOY_PATH = "/srv/devops/the-tip-top/${env.ENV}"
|
||
|
||
echo """
|
||
🌍 Environnement = ${env.ENV}
|
||
🏷️ Tag Docker = ${env.TAG}
|
||
📂 Chemin de déploiement = ${env.DEPLOY_PATH}
|
||
"""
|
||
}
|
||
}
|
||
}
|
||
|
||
stage('Checkout') {
|
||
steps {
|
||
echo "📦 Récupération du code source..."
|
||
checkout scm
|
||
}
|
||
}
|
||
|
||
stage('Tests & Qualité') {
|
||
agent {
|
||
docker {
|
||
image 'node:20'
|
||
args '-u root'
|
||
}
|
||
}
|
||
steps {
|
||
echo "🧪 Lancement des tests et analyse du code..."
|
||
script {
|
||
def lintStatus = sh(script: 'npm ci && npm run lint', returnStatus: true)
|
||
def testStatus = sh(script: 'npm test', returnStatus: true)
|
||
|
||
if (lintStatus != 0) {
|
||
error "❌ ESLint a échoué - Le déploiement est bloqué"
|
||
}
|
||
|
||
if (testStatus != 0) {
|
||
error "❌ Les tests ont échoué - Le déploiement est bloqué"
|
||
}
|
||
|
||
echo "✅ Tests et lint passés avec succès"
|
||
}
|
||
}
|
||
}
|
||
|
||
stage('Build Frontend') {
|
||
agent {
|
||
docker {
|
||
image 'node:20'
|
||
args '-u root'
|
||
}
|
||
}
|
||
steps {
|
||
echo "⚙️ Build de l’application Next.js..."
|
||
sh '''
|
||
npm ci
|
||
npm run build
|
||
'''
|
||
}
|
||
}
|
||
|
||
stage('Build Docker image') {
|
||
steps {
|
||
echo "🐳 Construction de l’image Docker frontend..."
|
||
sh """
|
||
docker build -t ${REGISTRY_URL}/${IMAGE_NAME}:${env.TAG} .
|
||
docker tag ${REGISTRY_URL}/${IMAGE_NAME}:${env.TAG} ${REGISTRY_URL}/${IMAGE_NAME}:latest
|
||
"""
|
||
}
|
||
}
|
||
|
||
stage('Push to Registry') {
|
||
steps {
|
||
echo "📤 Envoi de l’image vers le registre Docker..."
|
||
withCredentials([usernamePassword(credentialsId: 'registry-credentials', usernameVariable: 'REG_USER', passwordVariable: 'REG_PASS')]) {
|
||
sh """
|
||
echo "$REG_PASS" | docker login ${REGISTRY_URL} -u "$REG_USER" --password-stdin
|
||
docker push ${REGISTRY_URL}/${IMAGE_NAME}:${env.TAG}
|
||
docker push ${REGISTRY_URL}/${IMAGE_NAME}:latest
|
||
"""
|
||
}
|
||
}
|
||
}
|
||
|
||
stage('Backup before deploy') {
|
||
steps {
|
||
echo "💾 Sauvegarde avant déploiement (${env.ENV})..."
|
||
sh '''
|
||
BACKUP_DIR="/srv/backups/the-tip-top/${ENV}/$(date +%F_%H-%M-%S)"
|
||
mkdir -p $BACKUP_DIR
|
||
echo "📦 Sauvegarde du docker-compose et logs..."
|
||
cp -r ${DEPLOY_PATH}/docker-compose.yml $BACKUP_DIR/ 2>/dev/null || true
|
||
cp -r ${DEPLOY_PATH}/logs $BACKUP_DIR/ 2>/dev/null || true
|
||
tar -czf ${BACKUP_DIR}.tar.gz -C $(dirname $BACKUP_DIR) $(basename $BACKUP_DIR)
|
||
rm -rf $BACKUP_DIR
|
||
echo "✅ Sauvegarde compressée : ${BACKUP_DIR}.tar.gz"
|
||
'''
|
||
}
|
||
}
|
||
|
||
stage('Deploy') {
|
||
steps {
|
||
echo "🚀 Déploiement du frontend sur ${env.ENV}..."
|
||
sh """
|
||
cd "${env.DEPLOY_PATH}"
|
||
docker compose pull frontend
|
||
docker compose up -d --no-deps --force-recreate frontend
|
||
"""
|
||
}
|
||
}
|
||
}
|
||
|
||
post {
|
||
success {
|
||
echo "✅ Pipeline frontend ${env.ENV} terminé avec succès !"
|
||
}
|
||
failure {
|
||
echo "❌ Échec du pipeline frontend (${env.ENV})."
|
||
}
|
||
}
|
||
}
|