forked from Youssef-Choura/BookApp
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathJenkinsfile_Sonar
More file actions
64 lines (59 loc) · 1.73 KB
/
Jenkinsfile_Sonar
File metadata and controls
64 lines (59 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
pipeline {
agent any
tools {
git 'git'
maven 'Maven'
jdk 'JDK17'
}
environment {
// The SonarQube environment name configured in Jenkins
SONARQUBE_ENV = 'SonarQubeServer'
// The project key registered in SonarQube
SONAR_PROJECT_KEY = 'mybookapp_backend'
SONAR_HOST_URL = 'http://localhost:9000'
SONAR_AUTH_TOKEN = credentials('Sonarqube_Jenkins')
}
stages {
stage('Checkout') {
steps {
git 'https://github.com/mohansgithub/BookApp.git'
}
}
stage('Build') {
steps {
echo 'Building application...'
// Example for Maven project
bat 'mvn clean package -DskipTests'
}
}
stage('SonarQube Analysis') {
steps {
echo 'Running SonarQube analysis...'
withSonarQubeEnv("${SONARQUBE_ENV}") {
bat """
mvn sonar:sonar ^
-Dsonar.projectKey=%SONAR_PROJECT_KEY% ^
-Dsonar.host.url=%SONAR_HOST_URL% ^
-Dsonar.token=%SONAR_AUTH_TOKEN%
"""
}
}
}
stage('Quality Gate') {
steps {
echo 'Checking SonarQube Quality Gate result...'
timeout(time: 5, unit: 'MINUTES') {
waitForQualityGate abortPipeline: true
}
}
}
}
post {
success {
echo '✅ SonarQube analysis completed successfully!'
}
failure {
echo '❌ Build failed or Quality Gate not passed!'
}
}
}