From 009d22ff30ae4666933628c826fe6a15adc5ad61 Mon Sep 17 00:00:00 2001 From: Rohan Patel <85880033+Roro1727@users.noreply.github.com> Date: Mon, 30 Mar 2026 17:16:51 +0530 Subject: [PATCH] Update Jenkinsfile (SonarQube Integration) --- Jenkinsfile | 57 +++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 49 insertions(+), 8 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 2c0b4c87..133c9101 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -2,31 +2,72 @@ pipeline { agent any stages { - stage ('Compile Stage') { + stage('Compile Stage') { steps { - withMaven(maven : 'maven_3_5_0') { + withMaven(maven: 'maven_3_5_0') { sh 'mvn clean compile' } } } - stage ('Testing Stage') { - + stage('Testing Stage') { steps { - withMaven(maven : 'maven_3_5_0') { + withMaven(maven: 'maven_3_5_0') { sh 'mvn test' } } } + stage('SonarQube Analysis') { + steps { + withSonarQubeEnv('SonarQube') { // must match name configured in Jenkins + withMaven(maven: 'maven_3_5_0') { + sh ''' + mvn sonar:sonar \ + -Dsonar.projectKey=jenkins-example \ + -Dsonar.projectName="Jenkins Example" \ + -Dsonar.sources=src/main/java \ + -Dsonar.tests=src/test/java \ + -Dsonar.java.binaries=target/classes + ''' + } + } + } + } - stage ('Deployment Stage') { + stage('Quality Gate') { steps { - withMaven(maven : 'maven_3_5_0') { + timeout(time: 5, unit: 'MINUTES') { + waitForQualityGate abortPipeline: true + } + } + } + + stage('Deployment Stage') { + steps { + withMaven(maven: 'maven_3_5_0') { sh 'mvn deploy' } } } + } -} \ No newline at end of file +} +``` + +--- + +## Step 6: Run the Pipeline + +1. Go to your `jenkins-example` job +2. Click **Build Now** +3. Click the build number → **Console Output** to watch it live + +You should see all 5 stages execute in sequence: +``` +✅ Compile Stage +✅ Testing Stage +✅ SonarQube Analysis +✅ Quality Gate +✅ Deployment Stage