fix: run SonarQube after tests to include coverage report
The tests and SonarQube were running in parallel in separate Docker containers. This meant SonarQube never had access to the coverage/lcov.info file generated by Jest. Changes: - Run Lint & Tests stage first - Stash coverage report after tests - Run SonarQube stage after, unstashing coverage - Update pipeline documentation This fix ensures SonarQube receives the actual test coverage data. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
068b47ebe3
commit
72bdd21743
31
Jenkinsfile
vendored
31
Jenkinsfile
vendored
|
|
@ -9,7 +9,8 @@
|
|||
* 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)
|
||||
* 4a. Lint & Tests - ESLint + Jest avec couverture de code
|
||||
* 4b. SonarQube - Analyse statique (après tests pour avoir la couverture)
|
||||
* 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
|
||||
|
|
@ -130,21 +131,12 @@ pipeline {
|
|||
}
|
||||
|
||||
// =====================================================================
|
||||
// ÉTAPE 4 : CONTRÔLES QUALITÉ (Exécution parallèle)
|
||||
// ÉTAPE 4a : 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 {
|
||||
|
|
@ -167,19 +159,22 @@ pipeline {
|
|||
}
|
||||
echo "✅ Lint et tests passés avec succès"
|
||||
}
|
||||
// Stash coverage report for SonarQube
|
||||
stash includes: 'coverage/**', name: 'coverage'
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------
|
||||
// 4b. SONARQUBE
|
||||
// -------------------------------------------------------------
|
||||
// =====================================================================
|
||||
// ÉTAPE 4b : 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
|
||||
// -------------------------------------------------------------
|
||||
// NOTE: Exécuté APRÈS les tests pour avoir accès au rapport de couverture
|
||||
// =====================================================================
|
||||
stage('📊 SonarQube Analysis') {
|
||||
agent {
|
||||
docker {
|
||||
|
|
@ -188,6 +183,8 @@ pipeline {
|
|||
}
|
||||
}
|
||||
steps {
|
||||
// Unstash coverage report from tests
|
||||
unstash 'coverage'
|
||||
echo "📊 Analyse SonarQube en cours..."
|
||||
withSonarQubeEnv('SonarQube') {
|
||||
sh """
|
||||
|
|
@ -197,8 +194,6 @@ pipeline {
|
|||
echo "✅ Analyse SonarQube terminée"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// =====================================================================
|
||||
// ÉTAPE 5 : BUILD IMAGE DOCKER
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user