fix: run tests before SonarQube to share coverage report
- Tests now run sequentially before SonarQube (not in parallel) - Coverage report is stashed and passed to SonarQube stage - SonarQube will now see actual test coverage 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
2e0beec338
commit
27965e4cc2
47
Jenkinsfile
vendored
47
Jenkinsfile
vendored
|
|
@ -9,10 +9,11 @@
|
|||
* 1. Init - Détection de l'environnement (dev/preprod/prod)
|
||||
* 2. Checkout - Récupération du code source depuis Git
|
||||
* 3. Install - Installation des dépendances Node.js
|
||||
* 4. Quality - Vérification qualité (ESLint + Jest + SonarQube)
|
||||
* 5. Build - Construction de l'image Docker (avec variables env)
|
||||
* 6. Push - Envoi de l'image vers le registre Docker privé
|
||||
* 7. Deploy - Déploiement sur le serveur cible
|
||||
* 4. Lint & Tests - ESLint + Jest avec couverture de code
|
||||
* 5. SonarQube - Analyse statique avec rapport de couverture
|
||||
* 6. Build - Construction de l'image Docker (avec variables env)
|
||||
* 7. Push - Envoi de l'image vers le registre Docker privé
|
||||
* 8. Deploy - Déploiement sur le serveur cible
|
||||
*
|
||||
* ENVIRONNEMENTS :
|
||||
* - dev : Développement (branche dev)
|
||||
|
|
@ -130,21 +131,12 @@ pipeline {
|
|||
}
|
||||
|
||||
// =====================================================================
|
||||
// ÉTAPE 4 : CONTRÔLES QUALITÉ (Exécution parallèle)
|
||||
// ÉTAPE 4 : LINT & TESTS
|
||||
// ---------------------------------------------------------------------
|
||||
// Exécute en parallèle :
|
||||
// - Lint & Tests : ESLint + Jest avec couverture de code
|
||||
// - SonarQube : Analyse statique de la qualité du code
|
||||
// =====================================================================
|
||||
stage('🔍 Quality - Contrôles qualité') {
|
||||
parallel {
|
||||
// -------------------------------------------------------------
|
||||
// 4a. LINT & TESTS
|
||||
// -------------------------------------------------------------
|
||||
// ESLint : Vérifie le style et les erreurs de code
|
||||
// Jest : Exécute les tests unitaires React/Next.js
|
||||
// Couverture : Génère un rapport de couverture (lcov)
|
||||
// -------------------------------------------------------------
|
||||
// =====================================================================
|
||||
stage('🧪 Lint & Tests') {
|
||||
agent {
|
||||
docker {
|
||||
|
|
@ -157,7 +149,10 @@ pipeline {
|
|||
echo "🧪 Lancement ESLint et Jest..."
|
||||
script {
|
||||
def lintStatus = sh(script: 'npm run lint', returnStatus: true)
|
||||
def testStatus = sh(script: 'npm test', returnStatus: true)
|
||||
def testStatus = sh(script: 'npm test -- --coverage', returnStatus: true)
|
||||
|
||||
// Stash coverage report for SonarQube
|
||||
stash includes: 'coverage/**', name: 'coverage', allowEmpty: true
|
||||
|
||||
if (lintStatus != 0) {
|
||||
error "❌ ESLint a échoué - Corrigez les erreurs de style"
|
||||
|
|
@ -170,16 +165,16 @@ pipeline {
|
|||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------
|
||||
// 4b. SONARQUBE
|
||||
// -------------------------------------------------------------
|
||||
// =====================================================================
|
||||
// ÉTAPE 5 : SONARQUBE
|
||||
// ---------------------------------------------------------------------
|
||||
// Analyse statique du code pour détecter :
|
||||
// - Bugs potentiels
|
||||
// - Vulnérabilités de sécurité
|
||||
// - Code smells (mauvaises pratiques)
|
||||
// - Couverture de code insuffisante
|
||||
// - Duplications de code
|
||||
// -------------------------------------------------------------
|
||||
// =====================================================================
|
||||
stage('📊 SonarQube Analysis') {
|
||||
agent {
|
||||
docker {
|
||||
|
|
@ -188,7 +183,9 @@ pipeline {
|
|||
}
|
||||
}
|
||||
steps {
|
||||
echo "📊 Analyse SonarQube en cours..."
|
||||
// Unstash coverage report from tests
|
||||
unstash 'coverage'
|
||||
echo "📊 Analyse SonarQube en cours avec rapport de couverture..."
|
||||
withSonarQubeEnv('SonarQube') {
|
||||
sh """
|
||||
sonar-scanner
|
||||
|
|
@ -197,11 +194,9 @@ pipeline {
|
|||
echo "✅ Analyse SonarQube terminée"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// =====================================================================
|
||||
// ÉTAPE 5 : BUILD IMAGE DOCKER
|
||||
// ÉTAPE 6 : BUILD IMAGE DOCKER
|
||||
// ---------------------------------------------------------------------
|
||||
// But : Construire l'image Docker du frontend Next.js
|
||||
// Spécificité : Injection des variables NEXT_PUBLIC_* au build time
|
||||
|
|
@ -237,7 +232,7 @@ pipeline {
|
|||
}
|
||||
|
||||
// =====================================================================
|
||||
// ÉTAPE 6 : PUSH VERS LE REGISTRE
|
||||
// ÉTAPE 7 : PUSH VERS LE REGISTRE
|
||||
// ---------------------------------------------------------------------
|
||||
// But : Envoyer l'image Docker vers le registre privé
|
||||
// Registre : registry.wk-archi-o24a-15m-g3.fr
|
||||
|
|
@ -258,7 +253,7 @@ pipeline {
|
|||
}
|
||||
|
||||
// =====================================================================
|
||||
// ÉTAPE 7 : DÉPLOIEMENT
|
||||
// ÉTAPE 8 : DÉPLOIEMENT
|
||||
// ---------------------------------------------------------------------
|
||||
// But : Déployer le frontend sur le serveur cible
|
||||
// Actions :
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user