forked from PegaSysEng/pantheon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
232 lines (219 loc) · 9.05 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
224
225
226
227
228
229
230
231
232
#!/usr/bin/env groovy
import hudson.model.Result
import hudson.model.Run
import jenkins.model.CauseOfInterruption.UserInterruption
if (env.BRANCH_NAME == "master") {
properties([
buildDiscarder(
logRotator(
daysToKeepStr: '90'
)
)
])
} else {
properties([
buildDiscarder(
logRotator(
numToKeepStr: '10'
)
)
])
}
def docker_image_dind = 'docker:18.06.0-ce-dind'
def docker_image = 'docker:18.06.0-ce'
def build_image = 'pegasyseng/pantheon-build:0.0.5-jdk11'
def abortPreviousBuilds() {
Run previousBuild = currentBuild.rawBuild.getPreviousBuildInProgress()
while (previousBuild != null) {
if (previousBuild.isInProgress()) {
def executor = previousBuild.getExecutor()
if (executor != null) {
echo ">> Aborting older build #${previousBuild.number}"
executor.interrupt(Result.ABORTED, new UserInterruption(
"Aborted by newer build #${currentBuild.number}"
))
}
}
previousBuild = previousBuild.getPreviousBuildInProgress()
}
}
abortPreviousBuilds()
try {
parallel UnitTests: {
def stage_name = "Unit tests node: "
node {
checkout scm
docker.image(docker_image_dind).withRun('--privileged') { d ->
docker.image(build_image).inside("--link ${d.id}:docker") {
try {
stage(stage_name + 'Prepare') {
sh './gradlew --no-daemon --parallel clean compileJava compileTestJava assemble'
}
stage(stage_name + 'Unit tests') {
sh './gradlew --no-daemon --parallel build'
}
} finally {
archiveArtifacts '**/build/reports/**'
archiveArtifacts '**/build/test-results/**'
archiveArtifacts 'build/reports/**'
archiveArtifacts 'build/distributions/**'
stash allowEmpty: true, includes: 'build/distributions/pantheon-*.tar.gz', name: 'distTarBall'
junit '**/build/test-results/**/*.xml'
}
}
}
}
}, ReferenceTests: {
def stage_name = "Reference tests node: "
node {
checkout scm
docker.image(docker_image_dind).withRun('--privileged') { d ->
docker.image(build_image).inside("--link ${d.id}:docker") {
try {
stage(stage_name + 'Prepare') {
sh './gradlew --no-daemon --parallel clean compileJava compileTestJava assemble'
}
stage(stage_name + 'Reference tests') {
sh './gradlew --no-daemon --parallel referenceTest'
}
} finally {
archiveArtifacts '**/build/reports/**'
archiveArtifacts '**/build/test-results/**'
archiveArtifacts 'build/reports/**'
archiveArtifacts 'build/distributions/**'
junit '**/build/test-results/**/*.xml'
}
}
}
}
}, IntegrationTests: {
def stage_name = "Integration tests node: "
node {
checkout scm
docker.image(docker_image_dind).withRun('--privileged') { d ->
docker.image(build_image).inside("--link ${d.id}:docker") {
try {
stage(stage_name + 'Prepare') {
sh './gradlew --no-daemon --parallel clean compileJava compileTestJava assemble'
}
stage(stage_name + 'Integration Tests') {
sh './gradlew --no-daemon --parallel integrationTest'
}
stage(stage_name + 'Check Licenses') {
sh './gradlew --no-daemon --parallel checkLicenses'
}
stage(stage_name + 'Check javadoc') {
sh './gradlew --no-daemon --parallel javadoc'
}
stage(stage_name + 'Compile Benchmarks') {
sh './gradlew --no-daemon --parallel compileJmh'
}
} finally {
archiveArtifacts '**/build/reports/**'
archiveArtifacts '**/build/test-results/**'
archiveArtifacts 'build/reports/**'
archiveArtifacts 'build/distributions/**'
junit '**/build/test-results/**/*.xml'
}
}
}
}
}, AcceptanceTests: {
def stage_name = "Acceptance tests node: "
node {
checkout scm
docker.image(docker_image_dind).withRun('--privileged') { d ->
docker.image(build_image).inside("--link ${d.id}:docker") {
try {
stage(stage_name + 'Prepare') {
sh './gradlew --no-daemon --parallel clean compileJava compileTestJava assemble'
}
stage(stage_name + 'Acceptance Tests') {
sh './gradlew --no-daemon --parallel acceptanceTest'
}
} finally {
archiveArtifacts '**/build/reports/**'
archiveArtifacts '**/build/test-results/**'
archiveArtifacts 'build/reports/**'
archiveArtifacts 'build/distributions/**'
junit '**/build/test-results/**/*.xml'
}
}
}
}
}, DocTests: {
def stage_name = "Documentation tests node: "
node {
checkout scm
stage(stage_name + 'Build') {
def container = docker.image("python:3-alpine").inside() {
try {
sh 'pip install -r docs/requirements.txt'
sh 'mkdocs build -s'
} catch(e) {
throw e
}
}
}
}
}
if (env.BRANCH_NAME == "master") {
node {
checkout scm
unstash 'distTarBall'
docker.image(docker_image_dind).withRun('--privileged') { d ->
docker.image(docker_image).inside("-e DOCKER_HOST=tcp://docker:2375 --link ${d.id}:docker") {
stage('build image') {
sh "cd docker && cp ../build/distributions/pantheon-*.tar.gz ."
pantheon = docker.build("pegasyseng/pantheon:develop", "docker")
}
try {
stage('test image') {
sh "apk add bash"
sh "mkdir -p docker/reports"
sh "cd docker && bash test.sh pegasyseng/pantheon:develop"
}
} finally {
junit 'docker/reports/*.xml'
sh "rm -rf docker/reports"
}
stage('push image') {
docker.withRegistry('https://registry.hub.docker.com', 'dockerhub-pegasysengci') {
pantheon.push()
}
}
}
}
}
}
} catch (e) {
currentBuild.result = 'FAILURE'
} finally {
// If we're on master and it failed, notify slack
if (env.BRANCH_NAME == "master") {
def currentResult = currentBuild.result ?: 'SUCCESS'
def channel = '#priv-pegasys-prod-dev'
if (currentResult == 'SUCCESS') {
def previousResult = currentBuild.previousBuild?.result
if (previousResult != null && (previousResult == 'FAILURE' || previousResult == 'UNSTABLE')) {
slackSend(
color: 'good',
message: "Pantheon branch ${env.BRANCH_NAME} build is back to HEALTHY.\nBuild Number: #${env.BUILD_NUMBER}\n${env.BUILD_URL}",
channel: channel
)
}
} else if (currentBuild.result == 'FAILURE') {
slackSend(
color: 'danger',
message: "Pantheon branch ${env.BRANCH_NAME} build is FAILING.\nBuild Number: #${env.BUILD_NUMBER}\n${env.BUILD_URL}",
channel: channel
)
} else if (currentBuild.result == 'UNSTABLE') {
slackSend(
color: 'warning',
message: "Pantheon branch ${env.BRANCH_NAME} build is UNSTABLE.\nBuild Number: #${env.BUILD_NUMBER}\n${env.BUILD_URL}",
channel: channel
)
}
}
}