-
Notifications
You must be signed in to change notification settings - Fork 6
/
Jenkinsfile
342 lines (304 loc) · 12.7 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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
@Library('ecdc-pipeline')
import ecdcpipeline.ContainerBuildNode
import ecdcpipeline.PipelineBuilder
project = "event-formation-unit"
module_src="${project}/src/modules/"
coverage_on = "centos7"
clangformat_os = "debian11"
archive_what = "centos7-release"
// Set number of old builds to keep.
properties([[
$class: 'BuildDiscarderProperty',
strategy: [
$class: 'LogRotator',
artifactDaysToKeepStr: '',
artifactNumToKeepStr: '10',
daysToKeepStr: '',
numToKeepStr: ''
]
]]);
container_build_nodes = [
'almalinux8': ContainerBuildNode.getDefaultContainerBuildNode('almalinux8-gcc12'),
'centos7': ContainerBuildNode.getDefaultContainerBuildNode('centos7-gcc11'),
'centos7-release': ContainerBuildNode.getDefaultContainerBuildNode('centos7-gcc11'),
'debian11': ContainerBuildNode.getDefaultContainerBuildNode('debian11'),
'ubuntu2204': ContainerBuildNode.getDefaultContainerBuildNode('ubuntu2204')
]
def error_messages = []
def failure_function(exception_obj, failureMessage) {
def emailmap = [ "mortenjc@jcaps.com":"morten.christensen@ess.eu", \
"28659574+amues@users.noreply.github.com": "afonso.mukai@ess.eu"]
COMMITEMAIL = sh (
script: 'git --no-pager show -s --format=\'%ae\' 2> /dev/null || echo "none"',
returnStdout: true
).trim()
COMMITNAME = sh (
script: 'git --no-pager show -s --format=\'%an\' 2> /dev/null || echo "none"',
returnStdout: true
).trim()
EXTRATEXT="uninitialized"
TOMAIL='no email'
if (!COMMITEMAIL.contains("ess.eu")) {
if (emailmap.containsKey(COMMITEMAIL)) {
EXTRATEXT="non ess.eu - found in mail map"
TOMAIL= emailmap.get(COMMITEMAIL)
} else {
EXTRATEXT="non ess.eu - not found in mail map"
TOMAIL='morten.christensen@ess.eu'
}
} else {
EXTRATEXT="ess.eu - no lookup"
TOMAIL=COMMITEMAIL
}
def toEmails = [[$class: 'DevelopersRecipientProvider']]
emailext body: '${DEFAULT_CONTENT}\n\"' + failureMessage \
+ '\"\n\nCheck console output at $BUILD_URL to view the results.\n\n' \
+ 'Committer: ' + COMMITNAME + '\n' + 'Email:' + COMMITEMAIL \
+ '\n' + EXTRATEXT + '\n mapped to: ' + TOMAIL,
to: TOMAIL,
subject: '${DEFAULT_SUBJECT}'
}
pipeline_builder = new PipelineBuilder(this, container_build_nodes, "/mnt/data:/home/jenkins/refdata")
pipeline_builder.activateEmailFailureNotifications()
builders = pipeline_builder.createBuilders { container ->
pipeline_builder.stage("${container.key}: checkout") {
dir(pipeline_builder.project) {
scm_vars = checkout scm
}
// Copy source code to container
container.copyTo(pipeline_builder.project, pipeline_builder.project)
} // stage
if (container.key != clangformat_os) {
pipeline_builder.stage("${container.key}: get dependencies") {
container.sh """
cd ${project}
mkdir build
cd build
conan install --build=outdated ..
conan info ../conanfile.txt > CONAN_INFO
"""
} // stage
pipeline_builder.stage("${container.key}: configure") {
def xtra_flags = ""
if (container.key == coverage_on) {
xtra_flags = "-DCOV=ON"
} else if (container.key == archive_what) {
xtra_flags = "-DCMAKE_BUILD_TYPE=Release -DCMAKE_SKIP_BUILD_RPATH=ON"
}
container.sh """
cd ${project}/build
. ./activate_run.sh
cmake --version
cmake -DREFDATA=/home/jenkins/refdata/EFU_reference -DCONAN=MANUAL -DGOOGLE_BENCHMARK=ON ${xtra_flags} ..
"""
} // stage
pipeline_builder.stage("${container.key}: build") {
container.sh """
cd ${project}/build
make --version
make -j${pipeline_builder.numMakeJobs} all unit_tests benchmark
make
"""
} // stage
}
if (container.key == clangformat_os) {
pipeline_builder.stage("${container.key}: cppcheck") {
try {
def test_output = "cppcheck.xml"
// Ignore file that crashes cppcheck
container.sh """
cd ${project}
cppcheck --version
cppcheck -j${pipeline_builder.numMakeJobs} -v `./cppcheck_exclude_tests.sh src` --platform=unix64 --force --enable=all -I ./src '--template={file},{line},{severity},{id},{message}' --xml --xml-version=2 ./src --output-file=${test_output}
"""
container.copyFrom("${project}", '.')
sh "mv -f ./${project}/* ./"
} catch (e) {
error_messages.push("Cppcheck step for (${container.key}) failed")
throw e
}
} // stage
recordIssues(tools: [cppCheck(pattern: 'cppcheck.xml')])
}
if (container.key == coverage_on) {
pipeline_builder.stage("${container.key}: test coverage") {
abs_dir = pwd()
try {
container.sh """
cd ${project}/build
. ./activate_run.sh
make -j${pipeline_builder.numMakeJobs} runefu
make coverage
echo skipping make -j${pipeline_builder.numMakeJobs} valgrind
"""
container.copyFrom("${project}", '.')
} catch(e) {
container.copyFrom("${project}/build/test_results", '.')
junit 'test_results/*.xml'
error_messages.push("Run tests (${container.key}) failed")
throw e
}
dir("${project}/build") {
junit 'test_results/*.xml'
sh "../jenkins/redirect_coverage.sh ./coverage/coverage.xml ${abs_dir}/${project}"
step([
$class: 'CoberturaPublisher',
autoUpdateHealth: true,
autoUpdateStability: true,
coberturaReportFile: 'coverage/coverage.xml',
failUnhealthy: false,
failUnstable: false,
maxNumberOfBuilds: 0,
onlyStable: false,
sourceEncoding: 'ASCII',
zoomCoverageChart: true
])
}
} // stage
} else if (container.key != clangformat_os) {
pipeline_builder.stage("${container.key}: tests") {
container.sh """
cd ${project}/build
. ./activate_run.sh
make runtest
make runefu
"""
} // stage
}
if (container.key == archive_what) {
pipeline_builder.stage("${container.key}: archive") {
container.sh """
mkdir -p archive/event-formation-unit
cp -r ${project}/build/bin archive/event-formation-unit
cp -r ${project}/build/generators archive/event-formation-unit
cp -r ${project}/build/lib archive/event-formation-unit
cp -r ${project}/build/licenses archive/event-formation-unit
mkdir archive/event-formation-unit/util
cp -r ${project}/utils/efushell archive/event-formation-unit/util
mkdir archive/event-formation-unit/configs
mkdir archive/event-formation-unit/data
cp ${project}/build/CONAN_INFO archive/event-formation-unit
# Create file with build information
touch archive/event-formation-unit/BUILD_INFO
echo 'Repository: ${project}/${env.BRANCH_NAME}' >> archive/event-formation-unit/BUILD_INFO
echo 'Commit: ${scm_vars.GIT_COMMIT}' >> archive/event-formation-unit/BUILD_INFO
echo 'Jenkins build: ${BUILD_NUMBER}' >> archive/event-formation-unit/BUILD_INFO
cd archive
tar czvf event-formation-unit-centos7.tar.gz event-formation-unit
"""
container.copyFrom("/home/jenkins/archive/event-formation-unit-centos7.tar.gz", '.')
container.copyFrom("/home/jenkins/archive/event-formation-unit/BUILD_INFO", '.')
archiveArtifacts "event-formation-unit-centos7.tar.gz,BUILD_INFO"
if (env.CHANGE_ID) {
// Stash archive for integration test
stash 'event-formation-unit-centos7.tar.gz'
}
}
}
}
def get_macos_pipeline()
{
return {
stage("macOS") {
timestamps {
node ("macos") {
// Delete workspace when build is done
cleanWs()
// temporary until all our repos have moved to using official flatbuffers and CLI11 conan packages
sh "conan remove -f FlatBuffers/*"
sh "conan remove -f OpenSSL/*"
sh "conan remove -f cli11/*"
abs_dir = pwd()
dir("${project}") {
checkout scm
}
dir("${project}/build") {
sh "conan install --build=outdated .."
sh "cmake -DREFDATA=/Users/jenkins/data/EFU_reference -DCONAN=MANUAL -DCMAKE_MACOSX_RPATH=ON .."
sh "make -j${pipeline_builder.numCpus}"
sh "make -j${pipeline_builder.numCpus} unit_tests"
sh "make runtest"
sh "make runefu"
}
}
}
}
}
}
// Script actions start here
//
timestamps {
node('docker') {
dir("${project}_code") {
stage('Checkout') {
try {
scm_vars = checkout scm
} catch (e) {
error_messages.push('Checkout failed')
throw e
}
}
// skip build process if message contains '[ci skip]'
pipeline_builder.abortBuildOnMagicCommitMessage()
stage("Static analysis") {
try {
sh "find . -name '*TestData.h' > exclude_cloc"
sh "find . -name 'gcovr' >> exclude_cloc"
sh "cloc --exclude-list-file=exclude_cloc --by-file --xml --out=cloc.xml ."
sh "xsltproc jenkins/cloc2sloccount.xsl cloc.xml > sloccount.sc"
sloccountPublish encoding: '', pattern: ''
} catch (e) {
error_messages.push('Static analysis failed')
throw e
}
}
}
if (env.ENABLE_MACOS_BUILDS.toUpperCase() == 'TRUE') {
// Add macOS pipeline to builders
builders['macOS'] = get_macos_pipeline()
}
try {
timeout(time: 2, unit: 'HOURS') {
// run all builders in parallel
parallel builders
}
} catch (e) {
dir("${project}_code") {
failure_function(e, error_messages.join("\n"))
}
throw e
} finally {
// Delete workspace when build is done
cleanWs()
}
}
}
if (env.CHANGE_ID) {
// This is a pull request build
node('inttest') {
stage('Integration Test') {
sh "rm -rf build"
checkout scm
unstash 'event-formation-unit-centos7.tar.gz'
sh "tar xzvf event-formation-unit-centos7.tar.gz"
sh "mv event-formation-unit build"
sh """
export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:./build/lib/
python3 -u ./test/integrationtest.py
"""
} // stage
} // node
node('perftest'){
stage('Performance Test'){
sh "rm -rf build"
checkout scm
unstash 'event-formation-unit-centos7.tar.gz'
sh "tar xzvf event-formation-unit-centos7.tar.gz"
sh "mv event-formation-unit build"
sh """
export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:./build/lib/
python3 -u ./test/performancetest.py
"""
}
}
} // if