-
Notifications
You must be signed in to change notification settings - Fork 28
/
Jenkinsfile
223 lines (213 loc) · 7.82 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
pipeline {
environment {
devRegistry = 'ghcr.io/datakaveri/rs-dev'
deplRegistry = 'ghcr.io/datakaveri/rs-depl'
testRegistry = 'ghcr.io/datakaveri/rs-test:latest'
registryUri = 'https://ghcr.io'
registryCredential = 'datakaveri-ghcr'
GIT_HASH = GIT_COMMIT.take(7)
}
agent {
node {
label 'slave1'
}
}
stages {
stage('Build images') {
steps{
script {
echo 'Pulled - ' + env.GIT_BRANCH
devImage = docker.build( devRegistry, "-f ./docker/dev.dockerfile .")
deplImage = docker.build( deplRegistry, "-f ./docker/depl.dockerfile .")
testImage = docker.build( testRegistry, "-f ./docker/test.dockerfile .")
}
}
}
stage('Unit Tests and Code Coverage Test'){
steps{
script{
sh 'docker compose -f docker-compose.test.yml up test'
}
xunit (
thresholds: [ skipped(failureThreshold: '40'), failed(failureThreshold: '0') ],
tools: [ JUnit(pattern: 'target/surefire-reports/*.xml') ]
)
jacoco classPattern: 'target/classes', execPattern: 'target/jacoco.exec', sourcePattern: 'src/main/java', exclusionPattern:'iudx/resource/server/apiserver/ApiServerVerticle.class,**/*VertxEBProxy.class,**/Constants.class,**/*VertxProxyHandler.class,**/*Verticle.class,iudx/resource/server/database/archives/DatabaseService.class,iudx/resource/server/database/async/AsyncService.class,iudx/resource/server/database/latest/LatestDataService.class,iudx/resource/server/deploy/*.class,iudx/resource/server/database/postgres/PostgresService.class,iudx/resource/server/apiserver/ManagementRestApi.class,iudx/resource/server/apiserver/AdminRestApi.class,iudx/resource/server/apiserver/AsyncRestApi.class,iudx/resource/server/callback/CallbackService.class,**/JwtDataConverter.class,**/EncryptionService.class,**/EsResponseFormatter.class,**/AbstractEsSearchResponseFormatter.class'
}
post{
always {
recordIssues(
enabledForFailure: true,
skipBlames: true,
qualityGates: [[threshold:0, type: 'TOTAL', unstable: false]],
tool: checkStyle(pattern: 'target/checkstyle-result.xml')
)
recordIssues(
enabledForFailure: true,
skipBlames: true,
qualityGates: [[threshold:5, type: 'TOTAL', unstable: false]],
tool: pmdParser(pattern: 'target/pmd.xml')
)
}
failure{
script{
sh 'docker compose -f docker-compose.test.yml down --remove-orphans'
}
error "Test failure. Stopping pipeline execution!"
}
cleanup{
script{
sh 'sudo rm -rf target/'
}
}
}
}
stage('Start Resource-Server for Performance and Integration Testing'){
steps{
script{
sh 'scp Jmeter/ResourceServer.jmx jenkins@jenkins-master:/var/lib/jenkins/iudx/rs/Jmeter/'
sh 'docker compose -f docker-compose.test.yml up -d perfTest'
sh 'sleep 60'
}
}
post{
failure{
script{
sh 'docker compose -f docker-compose.test.yml down --remove-orphans'
}
}
}
}
stage('Jmeter Performance Test'){
steps{
script{
env.puneToken = sh(returnStdout: true, script: 'python3 Jenkins/resources/get-token.py --pune').trim()
env.suratToken = sh(returnStdout: true, script: 'python3 Jenkins/resources/get-token.py --surat').trim()
}
node('built-in') {
script{
sh 'rm -rf /var/lib/jenkins/iudx/rs/Jmeter/report ; mkdir -p /var/lib/jenkins/iudx/rs/Jmeter/report'
sh "set +x;/var/lib/jenkins/apache-jmeter/bin/jmeter.sh -n -t /var/lib/jenkins/iudx/rs/Jmeter/ResourceServer.jmx -l /var/lib/jenkins/iudx/rs/Jmeter/report/JmeterTest.jtl -e -o /var/lib/jenkins/iudx/rs/Jmeter/report/ -Jhost=jenkins-slave1 -Jport=8080 -Jprotocol=http -JpuneToken=$env.puneToken -JsuratToken=$env.suratToken"
}
perfReport filterRegex: '', showTrendGraphs: true, sourceDataFiles: '/var/lib/jenkins/iudx/rs/Jmeter/report/*.jtl'
}
}
post{
failure{
script{
sh 'docker compose -f docker-compose.test.yml down --remove-orphans'
}
}
}
}
stage('Integration Tests and OWASP ZAP pen test'){
steps{
node('built-in') {
script{
startZap ([host: '0.0.0.0', port: 8090, zapHome: '/var/lib/jenkins/tools/com.cloudbees.jenkins.plugins.customtools.CustomTool/OWASP_ZAP/ZAP_2.11.0'])
sh 'curl http://0.0.0.0:8090/JSON/pscan/action/disableScanners/?ids=10096'
}
}
script{
sh 'mkdir -p configs'
sh 'scp /home/ubuntu/configs/rs-config-test.json ./configs/config-test.json'
sh 'mvn test-compile failsafe:integration-test -DskipUnitTests=true -DintTestProxyHost=jenkins-master-priv -DintTestProxyPort=8090 -DintTestHost=jenkins-slave1 -DintTestPort=8080'
}
node('built-in') {
script{
runZapAttack()
}
}
}
post{
always{
xunit (
thresholds: [ skipped(failureThreshold: '0'), failed(failureThreshold: '0') ],
tools: [ JUnit(pattern: 'target/failsafe-reports/*.xml') ]
)
node('built-in') {
script{
archiveZap failHighAlerts: 1, failMediumAlerts: 1, failLowAlerts: 1
}
}
}
failure{
error "Test failure. Stopping pipeline execution!"
}
cleanup{
script{
sh 'docker compose -f docker-compose.test.yml down --remove-orphans'
}
}
}
}
stage('Continuous Deployment') {
when {
allOf {
anyOf {
changeset "docker/**"
changeset "docs/**"
changeset "pom.xml"
changeset "src/main/**"
triggeredBy cause: 'UserIdCause'
}
expression {
return env.GIT_BRANCH == 'origin/master';
}
}
}
stages {
stage('Push Images') {
steps {
script {
docker.withRegistry( registryUri, registryCredential ) {
devImage.push("5.6.0-alpha-${env.GIT_HASH}")
deplImage.push("5.6.0-alpha-${env.GIT_HASH}")
}
}
}
}
stage('Docker Swarm deployment') {
steps {
script {
sh "ssh azureuser@docker-swarm 'docker service update rs_rs --image ghcr.io/datakaveri/rs-depl:5.6.0-alpha-${env.GIT_HASH}'"
sh 'sleep 60'
}
}
post{
failure{
error "Failed to deploy image in Docker Swarm"
}
}
}
stage('Integration test on swarm deployment') {
steps {
script{
sh 'mvn test-compile failsafe:integration-test -DskipUnitTests=true -DintTestDepl=true'
}
}
post{
always{
xunit (
thresholds: [ skipped(failureThreshold: '0'), failed(failureThreshold: '0') ],
tools: [ JUnit(pattern: 'target/failsafe-reports/*.xml') ]
)
}
failure{
error "Test failure. Stopping pipeline execution!"
}
}
}
}
}
}
post{
failure{
script{
if (env.GIT_BRANCH == 'origin/master')
emailext recipientProviders: [buildUser(), developers()], to: '$RS_RECIPIENTS, $DEFAULT_RECIPIENTS', subject: '$PROJECT_NAME - Build # $BUILD_NUMBER - $BUILD_STATUS!', body: '''$PROJECT_NAME - Build # $BUILD_NUMBER - $BUILD_STATUS:
Check console output at $BUILD_URL to view the results.'''
}
}
}
}