forked from seqan/seqan3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.jenkinsfile
337 lines (301 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
import hudson.triggers.TimerTrigger;
// ============================================================================
// Global properties
// ============================================================================
// Only one build at a time for each branch/PR
// Start build every night between 1:00-4:59
// Keep only last 10 builds
properties([
pipelineTriggers(
[cron(env.BRANCH_NAME == 'master' ? 'H H(1-4) * * *' : '')]
),
buildDiscarder(
logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '10')
)
])
// ============================================================================
// Stop current build if superseded by new one.
// ============================================================================
// Cancels active build if there was a new one.
@NonCPS
def cancel_previous_builds()
{
def job_name = env.JOB_NAME
def build_number = env.BUILD_NUMBER.toInteger()
// Get job name
def currentJob = Jenkins.instance.getItemByFullName(job_name)
// Iterating over the builds for specific job
for (def build : currentJob.builds)
{
// If there is a build that is currently running and it's not current build
if (build.isBuilding() && build.number.toInteger() != build_number)
build.doStop()
}
}
cancel_previous_builds()
// ============================================================================
// Nightly execution
// ============================================================================
// Checks whether the current build was triggered by cron job.
// We need this to check, whether we want to trigger a deployment
// step for a stable nightly build.
def is_triggered_by_cron()
{
for (cause in currentBuild.rawBuild.getCauses())
{
if (cause instanceof TimerTrigger.TimerTriggerCause)
return true
return false
}
}
// Check if this build is a nightly build (only master supports building periodically)
Boolean is_nightly = is_triggered_by_cron()
// ============================================================================
// Define test functions
// ============================================================================
/* Executes unit tests
* \param slave_name The name of the slave this test is executed on; String
* \param compiler The name of the compiler to use; String
* \param build_type The build type to use [Debug, Release]; String
* \param model The model [Nightly, Continuous]; String
* \param with_cereal Whether to build with cereal support; Boolean
*/
def run_unit_tests(slave_name, compiler, build_type, model, with_cereal)
{
def build_name
def cxx
def disable_cereal
def workspace
def platform
stage ('versions')
{
sh "$compiler --version"
sh "cmake --version"
sh 'if [ -x "$(command -v doxygen)" ]; then doxygen --version; fi'
}
stage ('initialise')
{
workspace = pwd()
echo workspace
// Clean the workspace before building.
deleteDir()
build_name = "$slave_name $compiler cereal-$with_cereal $build_type $env.BRANCH_NAME Build-$env.BUILD_NUMBER"
disable_cereal = with_cereal ? 'OFF' : 'ON'
platform = sh(script: 'uname -s', returnStdout: true).trim()
sh 'git clone https://github.com/seqan/seqan3-infrastructure.git seqan3-infra'
cxx = sh(script: "which $compiler", returnStdout: true).trim()
// Perform checkout in specific location.
// The relative folder structure is important for the ctest script.
dir('checkout')
{
checkout scm
}
}
try
{
// Prepare environment and run ctest step.
withEnv(["BUILDNAME=$build_name",
"PLATFORM=$platform",
"MODEL=$model",
"TEST_MODEL=unit",
"WORKSPACE=$workspace",
"SITE_NAME=jenkins",
"DISABLE_CEREAL=$disable_cereal",
"CTEST_BUILD_TYPE=$build_type",
"CXX=$cxx"])
{
stage('run')
{
dir(workspace)
{
sh "ctest --no-compress-output -VV -S $workspace/seqan3-infra/ctest/seqan3_jenkins.cmake"
}
}
}
}
catch (Exception ex)
{
currentBuild.result = 'failure'
if (env.CHANGE_ID)
pullRequest.createStatus(status: 'failure',
context: 'continuous-integration/jenkins/pr-merge',
description: 'Running ctest failed.')
throw ex
}
finally
{ // cleanup
echo workspace
// Clean the workspace after building.
deleteDir()
}
}
// ============================================================================
// Define unit test matrix
// ============================================================================
// Configure unit tests. Add platforms here but adapt the inner loop of the matrix setup to call instantiate and
// setup the right agent.
def axis_agent = ["ubuntu", "osx"]
def axis_compiler = ["g++-7", "g++-8", "g++-9"] // clang-concepts
def axis_cereal = [true, false]
def axis_build_type =["Release", "Debug"]
def tasks = [:]
def CMAKE_VERSION = "3.7.2"
// The following nested for loops define the compiler matrix for the unit tests.
// First iterate over all supported compiler versions
// If the compilers do not match on the respective platform either use a different scope to
// iterate over them or define some kind of map to point to the right compiler name per platform.
for (int h = 0; h < axis_agent.size(); ++h)
{
def agent = axis_agent[h];
for(int i = 0; i < axis_compiler.size(); ++i)
{
def axis_compiler_value = axis_compiler[i]
// TODO: Enable once nested parallel sections can be displayed properly: https://issues.jenkins-ci.org/browse/JENKINS-54010
// def subTasks = [:] // defines subtask per platform & compiler;
for(int j = 0; j < axis_cereal.size(); ++j) // Whether to use cereal or not
{
def axis_cereal_value = axis_cereal[j]
// Only build nightlies with cereal disabled
if (!is_nightly && !axis_cereal_value)
continue
for (int k = 0; k < axis_build_type.size(); ++k) // Whether to build in release or debug mode
{
def axis_build_type_value = axis_build_type[k]
// Only build nightlies in debug mode
if (!is_nightly && (axis_build_type_value == "Debug"))
continue
def test_model = is_nightly ? 'Nightly' : 'Continuous'
def label = "${agent}_${axis_compiler_value}_cereal-${axis_cereal_value}_$axis_build_type_value"
tasks[label] =
{
if (agent == "osx") // build on macos
{
node("$agent && $axis_compiler_value")
{
run_unit_tests(env.NODE_NAME,
axis_compiler_value,
axis_build_type_value,
test_model,
axis_cereal_value)
}
}
else // build ubuntu
{
// Add node per platform here.
// They might differ in the usage and setup.
// Run on nodes matching labels 'ubuntu' and the compiler axis value.
// Only run g++-8 on ubuntu 1804 due to some linker errors on the ported package from ubuntu 1604
def platform = (axis_compiler_value == 'g++-8' ? 'ubuntu_1804' : 'ubuntu')
node("$platform && $axis_compiler_value")
{
// For docker nodes we need to define the workspace explicitly, as they use a mounted
// volume on the filesystem which is shared by all docker instances. Since the docker executor
// doesn't know the other running instances it cannot lock the workspace.
def workspace = "$env.SEQAN_BASE_DIR/ws/$env.JOB_NAME/$env.DOCKER_SLAVE_NAME/$env.BUILD_NUMBER/$label"
ws("$workspace")
{
stage('install')
{
sh """
mkdir -p /tmp/cmake-download
wget --no-clobber --directory-prefix=/tmp/cmake-download/ https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION}-Linux-x86_64.tar.gz
tar -C /tmp/ -zxvf /tmp/cmake-download/cmake-${CMAKE_VERSION}-Linux-x86_64.tar.gz
"""
sh """
sudo apt-get update
sudo apt-get install -y $axis_compiler_value make gcc git zlib1g-dev libbz2-dev
"""
}
withEnv(["HOME=$workspace","PATH+CMAKE_PATH=/tmp/cmake-${CMAKE_VERSION}-Linux-x86_64/bin"])
{
sh "echo $HOME"
run_unit_tests(env.DOCKER_SLAVE_NAME,
axis_compiler_value,
axis_build_type_value,
test_model,
axis_cereal_value)
}
}
}
}
}
}
}
// TODO: Enable once nested parallel sections can be displayed properly: https://issues.jenkins-ci.org/browse/JENKINS-54010
// tasks["${agent}-${axis_compiler_value}"] =
// {
// parallel subTasks
// }
}
}
/* TODO sanitizer builds
* g++-7 sanitizer options
*/
/* TODO doc builds
* user develop
*/
/* TODO coverage build
* g++-8 debug mode
*/
/* TODO valgrind build
*
*/
/* TODO performance build
* g++-7, g++-8 [, g++-9] [, clang-concpets]
*/
// ============================================================================
// Execute build matrix
// ============================================================================
// This is the main stage that executes all jobs registered in the tasks map
// All steps are executed in parallel. If the contention on the agents are to high
// consider moving some tasks out into another stage that runs after this one.
stage ("matrix")
{
parallel tasks
}
// ============================================================================
// Cleanup steps executed in the nightly builds
// ============================================================================
// Invokes some cleanup steps for the docker builds.
if (is_nightly)
{
stage ("cleanup")
{
// On the docker nodes we need to regularly check if a pull request was closed in order
// to remove the workspace which is stored persistently on the docker server.
node("ubuntu_1604 || ubuntu_1804")
{
// Get all open PRs and scan their PR number
String pulls = sh(script: "curl -X GET https://api.github.com/repos/seqan/seqan3/pulls", returnStdout: true).trim()
def change_ids = pulls.findAll(/number": (\d+),/)
{
match -> match[1]
}
dir("$env.SEQAN_BASE_DIR/ws/seqan3_build_pipeline")
{
def cache_folders = sh(returnStdout: true, script: 'ls').trim().split()
// Scan all existing folders if there is still a open PR for this.
for (folder in cache_folders)
{
def keep_alive = false
for (id in change_ids)
{
if (folder ==~ /^(?i)pr.${id}$/)
{
keep_alive = true
}
}
// If there isn't a direct match we can safely delete this workspace.
if (!keep_alive)
{
dir (folder)
{
echo "Removing diretory " + pwd()
deleteDir()
}
}
}
}
}
}
}