forked from hyperledger-iroha/iroha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
399 lines (361 loc) · 14.2 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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
/**
* Copyright Soramitsu Co., Ltd. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
import org.jenkinsci.plugins.workflow.steps.FlowInterruptedException
def tasks = [:]
class Worker {
String label
int cpusAvailable
}
class Builder {
// can't get to work without 'static'
static class PostSteps {
List success = []
List failure = []
List unstable = []
List always = []
List aborted = []
}
List buildSteps = []
PostSteps postSteps
}
class Build {
String name = ''
String type = ''
Builder builder
Worker worker
}
def build(Build build) {
return {
node(build.worker.label) {
try {
echo "Worker: ${env.NODE_NAME}"
gitNotify ("Jenkins: " + build.name, "Started...", 'PENDING')
build.builder.buildSteps.each {
it()
}
if (currentBuild.currentResult == 'SUCCESS') {
build.builder.postSteps.success.each {
it()
}
} else if(currentBuild.currentResult == 'UNSTABLE') {
build.builder.postSteps.unstable.each {
it()
}
}
} catch(FlowInterruptedException e) {
print "Looks like we ABORTED"
currentBuild.result = 'ABORTED'
build.builder.postSteps.aborted.each {
it()
}
} catch(Exception e) {
print "Error was detected: " + e
currentBuild.result = 'FAILURE'
build.builder.postSteps.failure.each {
it()
}
}
// ALWAYS
finally {
if (currentBuild.currentResult == 'SUCCESS')
gitNotify ("Jenkins: " + build.name, "Finish", 'SUCCESS')
else
gitNotify ("Jenkins: " + build.name, currentBuild.currentResult, 'FAILURE')
build.builder.postSteps.always.each {
it()
}
}
}
}
}
// sanitise the string it should contain only 'key1=value1;key2=value2;...'
def cmd_sanitize(String cmd){
if (cmd.contains("//"))
return false
for (i in cmd.split(";")){
if (i.split("=").size() != 2 )
return false
for (j in i.split("=")){
if (j.trim().contains(" "))
return false
}
}
return true
}
def gitNotify (context, description, status, targetUrl='' ){
if (build_scenario != 'Nightly build') {
githubNotify context: context, credentialsId: 'SORABOT_TOKEN_AND_LOGIN', description: description, status: status, targetUrl: targetUrl
}
}
stage('Prepare environment'){
timestamps(){
node ('master') {
scmVars = checkout scm
def textVariables = load '.jenkinsci/text-variables.groovy'
properties([
parameters([
choice(choices: textVariables.param_chose_opt, description: textVariables.param_descriptions, name: 'build_scenario'),
string(defaultValue: '', description: textVariables.cmd_description, name: 'custom_cmd', trim: true)
]),
buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '30'))
])
environmentList = []
environment = [:]
environment = [
"CCACHE_DEBUG_DIR": "/opt/.ccache",
"CCACHE_RELEASE_DIR": "/opt/.ccache",
"DOCKER_REGISTRY_BASENAME": "hyperledger/iroha",
"IROHA_NETWORK": "iroha-${scmVars.CHANGE_ID}-${scmVars.GIT_COMMIT}-${env.BUILD_NUMBER}",
"IROHA_POSTGRES_HOST": "pg-${scmVars.CHANGE_ID}-${scmVars.GIT_COMMIT}-${env.BUILD_NUMBER}",
"IROHA_POSTGRES_USER": "pguser${scmVars.GIT_COMMIT}",
"IROHA_POSTGRES_PASSWORD": "${scmVars.GIT_COMMIT}",
"IROHA_POSTGRES_PORT": "5432",
"GIT_RAW_BASE_URL": "https://raw.githubusercontent.com/hyperledger/iroha"
]
// Define variable and params
//All variable and Default values
x64linux_compiler_list = ['gcc7']
mac_compiler_list = []
win_compiler_list = []
testing = true
testList = '(module)'
fuzzing = true // testing = true
benchmarking = true // testing = true
sanitize = false
cppcheck = false
coredumps = true
sonar = false
codestyle = false
coverage = false
coverage_mac = false
doxygen = false
build_type = 'Debug'
build_shared_libs = false
packageBuild = false
pushDockerTag = 'not-supposed-to-be-pushed'
packagePush = false
specialBranch = false
parallelism = 0
useBTF = false
use_libursa = false
forceDockerDevelopBuild = false
if (scmVars.GIT_LOCAL_BRANCH in ["master"] || env.TAG_NAME )
specialBranch = true
else
specialBranch = false
if (specialBranch){
// if specialBranch == true the release build will run, so set packagePush
packagePush = true
doxygen = true
}
if (scmVars.GIT_LOCAL_BRANCH == "master")
pushDockerTag = 'master'
else if (env.TAG_NAME)
pushDockerTag = env.TAG_NAME
else
pushDockerTag = 'not-supposed-to-be-pushed'
if (params.build_scenario == 'Default')
if ( scmVars.GIT_BRANCH.startsWith('PR-'))
if (BUILD_NUMBER == '1')
build_scenario='On open PR'
else
build_scenario='Commit in Open PR'
else
build_scenario='Branch commit'
else
build_scenario = params.build_scenario
print("Selected Build Scenario '${build_scenario}'")
switch(build_scenario) {
case 'Branch commit':
echo "All Default"
break;
case 'On open PR':
// Just hint, not the main way to Notify about build status.
gitNotify ("Jenkins: Merge to trunk", "Please, run: 'Before merge to trunk'", 'PENDING', env.JOB_URL + "/build")
mac_compiler_list = ['appleclang']
win_compiler_list = ['msvc']
testList = '()'
coverage = true
cppcheck = true
sonar = true
codestyle = true
break;
case 'Commit in Open PR':
gitNotify ("Jenkins: Merge to trunk", "Please, run: 'Before merge to trunk'", 'PENDING', env.JOB_URL + "/build")
echo "All Default"
break;
case 'Before merge to trunk':
gitNotify ("Jenkins: Merge to trunk", "Started...", 'PENDING')
x64linux_compiler_list = ['gcc7', 'gcc9', 'clang7' , 'clang9']
mac_compiler_list = ['appleclang']
win_compiler_list = ['msvc']
testing = true
testList = '()'
coverage = true
cppcheck = true
sonar = true
codestyle = true
useBTF = true
break;
case 'Nightly build':
x64linux_compiler_list = ['gcc7', 'gcc9', 'clang7' , 'clang9']
mac_compiler_list = ['appleclang']
win_compiler_list = ['msvc']
testing = true
testList = '()'
coverage = true
cppcheck = true
sonar = true
codestyle = true
useBTF = true
sanitize = true
specialBranch=false
packagePush=false
doxygen=false
break;
case 'Push demo':
build_type='Release'
testing=false
environment["DOCKER_REGISTRY_BASENAME"] = 'soramitsu/iroha'
pushDockerTag = scmVars.GIT_LOCAL_BRANCH.trim().replaceAll('/','-')
packageBuild=true
fuzzing=false
benchmarking=false
coredumps=false
packagePush=true
break;
case 'Custom command':
if (cmd_sanitize(params.custom_cmd)){
evaluate (params.custom_cmd)
// A very rare scenario when linux compiler is not selected but we still need coverage
if (x64linux_compiler_list.isEmpty() && coverage ){
coverage_mac = true
}
} else {
println("Unable to parse '${params.custom_cmd}'")
sh "exit 1"
}
break;
default:
println("The value build_scenario='${build_scenario}' is not implemented");
sh "exit 1"
break;
}
// convert dictionary to list
environment.each { e ->
environmentList.add("${e.key}=${e.value}")
}
echo """
specialBranch=${specialBranch}, packageBuild=${packageBuild}, pushDockerTag=${pushDockerTag}, packagePush=${packagePush}
testing=${testing}, testList=${testList}, parallelism=${parallelism}, useBTF=${useBTF}
x64linux_compiler_list=${x64linux_compiler_list}, mac_compiler_list=${mac_compiler_list}, win_compiler_list = ${win_compiler_list}"
sanitize=${sanitize}, cppcheck=${cppcheck}, fuzzing=${fuzzing}, benchmarking=${benchmarking}, coredumps=${coredumps}, sonar=${sonar},
codestyle=${codestyle},coverage=${coverage}, coverage_mac=${coverage_mac} doxygen=${doxygen}"
forceDockerDevelopBuild=${forceDockerDevelopBuild}, env.TAG_NAME=${env.TAG_NAME}
"""
print scmVars
print environmentList
// Load Scripts
def x64LinuxBuildScript = load '.jenkinsci/builders/x64-linux-build-steps.groovy'
def x64BuildScript = load '.jenkinsci/builders/x64-mac-build-steps.groovy'
def x64WinBuildScript = load '.jenkinsci/builders/x64-win-build-steps.groovy'
// Define Workers
x64LinuxWorker = new Worker(label: 'docker-build-agent', cpusAvailable: 4)
x64MacWorker = new Worker(label: 'mac', cpusAvailable: 4)
x64WinWorker = new Worker(label: 'windows-iroha-agent', cpusAvailable: 8)
// Define all possible steps
def x64LinuxBuildSteps
def x64LinuxPostSteps = new Builder.PostSteps()
if(!x64linux_compiler_list.isEmpty()){
x64LinuxBuildSteps = [{x64LinuxBuildScript.buildSteps(
parallelism==0 ?x64LinuxWorker.cpusAvailable : parallelism, x64linux_compiler_list, build_type, build_shared_libs, specialBranch, coverage,
testing, testList, cppcheck, sonar, codestyle, doxygen, packageBuild, sanitize, fuzzing, benchmarking, coredumps, useBTF, use_libursa, forceDockerDevelopBuild, environmentList)}]
//If "master" also run Release build
if(specialBranch && build_type == 'Debug'){
x64LinuxBuildSteps += [{x64LinuxBuildScript.buildSteps(
parallelism==0 ?x64LinuxWorker.cpusAvailable : parallelism, x64linux_compiler_list, 'Release', build_shared_libs, specialBranch, false,
false, testList, false, false, false, false, true, false, false, false, false, false, use_libursa, false, environmentList)}]
}
if (build_scenario == 'Before merge to trunk') {
// TODO 2019-08-14 lebdron: IR-600 Fix integration tests execution when built with shared libraries
// Build with shared libraries
x64LinuxBuildSteps += [{x64LinuxBuildScript.buildSteps(
parallelism==0 ?x64LinuxWorker.cpusAvailable : parallelism, ['gcc7'], build_type, true, false, false,
false, testList, false, false, false, false, false, false, fuzzing, benchmarking, false, useBTF, use_libursa, false, environmentList)}]
if (!use_libursa) {
// Force build with libursa
x64LinuxBuildSteps += [{x64LinuxBuildScript.buildSteps(
parallelism==0 ?x64LinuxWorker.cpusAvailable : parallelism, ['gcc7'], build_type, build_shared_libs, false, false,
testing, testList, false, false, false, false, false, false, fuzzing, benchmarking, coredumps, useBTF, true, false, environmentList)}]
}
}
x64LinuxPostSteps = new Builder.PostSteps(
always: [{x64LinuxBuildScript.alwaysPostSteps(scmVars, environmentList, coredumps)}],
success: [{x64LinuxBuildScript.successPostSteps(scmVars, packagePush, pushDockerTag, environmentList)}])
}
def x64MacBuildSteps
def x64MacBuildPostSteps = new Builder.PostSteps()
if(!mac_compiler_list.isEmpty()){
x64MacBuildSteps = [{x64BuildScript.buildSteps(parallelism==0 ?x64MacWorker.cpusAvailable : parallelism,
mac_compiler_list, build_type, coverage_mac, testing, testList, packageBuild, fuzzing, benchmarking, useBTF, environmentList)}]
//If "master" or "dev" also run Release build
if(specialBranch && build_type == 'Debug'){
x64MacBuildSteps += [{x64BuildScript.buildSteps(parallelism==0 ?x64MacWorker.cpusAvailable : parallelism,
mac_compiler_list, 'Release', false, false, testList, true, false, false, false, environmentList)}]
}
x64MacBuildPostSteps = new Builder.PostSteps(
always: [{x64BuildScript.alwaysPostSteps(environmentList)}],
success: [{x64BuildScript.successPostSteps(scmVars, packagePush, environmentList)}])
}
def x64WinBuildSteps
def x64WinBuildPostSteps = new Builder.PostSteps()
if(!win_compiler_list.isEmpty()){
x64WinBuildSteps = [{x64WinBuildScript.buildSteps(parallelism==0 ?x64WinWorker.cpusAvailable : parallelism,
win_compiler_list, build_type, false, testing, testList, packageBuild, useBTF, environmentList)}]
x64WinBuildPostSteps = new Builder.PostSteps(
always: [{x64WinBuildScript.alwaysPostSteps(environmentList)}],
success: [{x64WinBuildScript.successPostSteps(scmVars, packagePush, environmentList)}])
}
// Define builders
x64LinuxBuilder = new Builder(buildSteps: x64LinuxBuildSteps, postSteps: x64LinuxPostSteps)
x64MacBuilder = new Builder(buildSteps: x64MacBuildSteps, postSteps: x64MacBuildPostSteps )
x64WinBuilder = new Builder(buildSteps: x64WinBuildSteps, postSteps: x64WinBuildPostSteps )
// Define Build
x64LinuxBuild = new Build(name: "x86_64 Linux ${build_type}",
type: build_type,
builder: x64LinuxBuilder,
worker: x64LinuxWorker)
x64MacBuild = new Build(name: "Mac ${build_type}",
type: build_type,
builder: x64MacBuilder,
worker: x64MacWorker)
x64WinBuild = new Build(name: "Windows ${build_type}",
type: build_type,
builder: x64WinBuilder,
worker: x64WinWorker)
if(!x64linux_compiler_list.isEmpty())
tasks[x64LinuxBuild.name] = build(x64LinuxBuild)
if(!mac_compiler_list.isEmpty())
tasks[x64MacBuild.name] = build(x64MacBuild)
if(!win_compiler_list.isEmpty())
tasks[x64WinBuild.name] = build(x64WinBuild)
cleanWs()
parallel tasks
if(codestyle){
report_file = "${BUILD_URL}artifact/clang-format-report.txt"
line = sh(script: "curl -s ${report_file} | wc -l", returnStdout: true).trim().toInteger()
if ( line == 1 )
gitNotify ("Jenkins: ClangFormat", "SUCCESS", 'SUCCESS', report_file )
else
gitNotify ("Jenkins: ClangFormat", "You need to format ~ ${line/2} lines", 'FAILURE', report_file )
}
if (build_scenario == 'Before merge to trunk')
if (currentBuild.currentResult == 'SUCCESS')
gitNotify ("Jenkins: Merge to trunk", "Finish", 'SUCCESS')
else
gitNotify ("Jenkins: Merge to trunk", currentBuild.currentResult, 'FAILURE')
}
}
}