forked from buddy-works/simple-java-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
65 lines (59 loc) · 2.2 KB
/
Jenkinsfile
File metadata and controls
65 lines (59 loc) · 2.2 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
65
pipeline {
agent any
tools {
maven 'maven' // Ensure the correct Maven tool is configured
}
environment {
// SCANNER_HOME is not needed unless you're explicitly pointing to a specific path for the scanner
// SCANNER_HOME = tool 'my_sonar' // Path to SonarQube tool (not needed if using withSonarQubeEnv)
}
stages {
// Stage to checkout the code from Git
stage('Checkout') {
steps {
git branch: 'master', credentialsId: 'git_token', url: 'https://github.com/Hadakar-Kasturi/simple-java-project.git'
}
}
// Stage for SonarQube analysis
stage('SonarQube Analysis') {
steps {
withSonarQubeEnv('my_sonar') {
sh """
mvn clean install sonar:sonar \
-Dsonar.projectKey="Test-project-${env.BUILD_NUMBER}" \
-Dsonar.projectName="Test-Project - Build #${env.BUILD_NUMBER}" \
-Dsonar.qualitygate.wait=true \
-Dsonar.projectVersion=${BUILD_ID}
"""
}
}
}
// Stage to wait for and check the SonarQube Quality Gate status
stage('Quality Gate') {
steps {
script {
// Set a timeout to wait for the quality gate result
timeout(time: 5, unit: 'MINUTES') {
def qualityGate = waitForQualityGate() // Get quality gate result
if (qualityGate.status != 'OK') { // Check if the quality gate status is not OK
error "Quality Gate failed! Aborting pipeline." // Abort pipeline if it fails
}
}
}
}
}
}
// Post actions: cleanup or notifications
post {
always {
echo "Pipeline completed"
cleanWs() // Clean workspace after the build
}
success {
echo "Build and SonarQube analysis completed successfully!"
}
failure {
echo "Build failed. Please check the logs for more details."
}
}
}