-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathJenkinsfile
119 lines (102 loc) · 2.78 KB
/
Jenkinsfile
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
pipeline {
agent any
tools {
// Install the Maven version configured as "M3" and add it to the path.
maven "M3"
// Configure OpenJDK11 by adding JDK installation with the url to installation file
jdk "OpenJDK11"
}
stages {
stage('Build') {
steps {
// Get code from a GitHub repository
git 'https://github.com/gavinklfong/reactive-spring-forex-trade.git'
// Compile source code without running unit test
sh "mvn clean compile -P compile"
}
post {
failure {
script {
error "Compile failed"
}
}
}
}
stage('Unit Test') {
steps {
// Run test cases with tag "UnitTest"
sh "mvn test -P unit-test"
// Publish Jacoco report
step( [ $class: 'JacocoPublisher' ] )
}
post {
failure {
script {
error "Unit Test failed"
}
}
}
}
stage('Code Analysis') {
steps {
// Submit source code to sonarqube for analysis
// Since Sonarqube authenticates any incoming request, please generate token in sonarqube admin panel
// Then, configure the token as secret text in Jenkins
withSonarQubeEnv(credentialsId: 'sonarqube', installationName: 'sonarqube') { // You can override the credential to be used
sh 'mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.8.0.2131:sonar'
}
}
post {
// Abort all subsequent steps if the current step failed
failure {
script {
error "Code Analysis failed"
}
}
}
}
stage('Code Analysis - Quality Gate') {
steps {
// Wait for analysis result from sonarqube with 5 minutes timeout
// This step will return error if result is NOT passed
timeout(time: 5, unit: 'MINUTES') {
waitForQualityGate abortPipeline: true
}
}
post {
// Abort all subsequent steps if the current step failed
failure {
error "Code Analysis Quality Gate NOT Passed"
}
}
}
stage('Integeration Test') {
steps {
// Run test cases with tag "IntegrationTest"
sh "mvn test -P integration-test"
}
post {
// Abort all subsequent steps if the current step failed
failure {
script {
error "Integration Test failed"
}
}
}
}
stage('End-to-End Test') {
steps {
// Run test cases with tag "E2ETest"
sh "mvn verify -P e2e-test"
}
post {
// Abort all subsequent steps if the current step failed
failure {
script {
error "End-to-End Test failed"
}
}
}
}
}
}