This repository has been archived by the owner on Apr 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 297
/
Jenkinsfile-new
310 lines (274 loc) · 10.2 KB
/
Jenkinsfile-new
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
/**
* 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 ("New CI: " + 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 ("New CI: " + build.name, "Finish", 'SUCCESS')
else
gitNotify ("New CI: " + 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='' ){
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-new/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"
]
environment.each { e ->
environmentList.add("${e.key}=${e.value}")
}
// Define variable and params
//All variable and Default values
x64linux_compiler_list = ['gcc5']
mac_compiler_list = []
testing = true
testList = '(module)'
sanitize = false
cppcheck = false
fuzzing = false // x64linux_compiler_list= ['clang6'] testing = true testList = "(None)"
sonar = false
coverage = false
coverage_mac = false
doxygen = false
build_type = 'Debug'
packageBuild = false
pushDockerTag = 'not-supposed-to-be-pushed'
packagePush = false
specialBranch = false
parallelism = 0
useBTF = false
if (scmVars.GIT_LOCAL_BRANCH in ["master","develop"] || scmVars.CHANGE_BRANCH_LOCAL in ["develop"])
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 == "develop")
pushDockerTag = 'develop'
else if (scmVars.GIT_LOCAL_BRANCH == 'master')
pushDockerTag = 'latest'
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 ("New CI: Merge to trunk", "Please, run: 'Before merge to trunk'", 'PENDING', env.JOB_URL + "/build")
mac_compiler_list = ['appleclang']
coverage = true
cppcheck = true
sonar = true
break;
case 'Commit in Open PR':
gitNotify ("New CI: Merge to trunk", "Please, run: 'Before merge to trunk'", 'PENDING', env.JOB_URL + "/build")
echo "All Default"
break;
case 'Before merge to trunk':
gitNotify ("New CI: Merge to trunk", "Started...", 'PENDING')
x64linux_compiler_list = ['gcc5','gcc7', 'clang6' , 'clang7']
mac_compiler_list = ['appleclang']
testing = true
testList = '()'
coverage = true
cppcheck = true
sonar = true
useBTF = 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;
}
echo "specialBranch=${specialBranch}, packageBuild=${packageBuild}, pushDockerTag=${pushDockerTag}, packagePush=${packagePush} "
echo "testing=${testing}, testList=${testList}, parallelism=${parallelism}, useBTF=${useBTF}"
echo "x64linux_compiler_list=${x64linux_compiler_list}"
echo "mac_compiler_list=${mac_compiler_list}"
echo "sanitize=${sanitize}, cppcheck=${cppcheck}, fuzzing=${fuzzing}, sonar=${sonar}, coverage=${coverage}, coverage_mac=${coverage_mac} doxygen=${doxygen}"
print scmVars
print environmentList
// Load Scripts
def x64LinuxBuildScript = load '.jenkinsci-new/builders/x64-linux-build-steps.groovy'
def x64BuildScript = load '.jenkinsci-new/builders/x64-mac-build-steps.groovy'
// Define Workers
x64LinuxWorker = new Worker(label: 'docker-build-agent', cpusAvailable: 8)
x64MacWorker = new Worker(label: 'mac', cpusAvailable: 4)
// 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, specialBranch, coverage,
testing, testList, cppcheck, sonar, doxygen, packageBuild, sanitize, fuzzing, useBTF, environmentList)}]
//If "master" or "dev" also run Release build
if(specialBranch && build_type == 'Debug'){
x64LinuxBuildSteps += [{x64LinuxBuildScript.buildSteps(
parallelism==0 ?x64LinuxWorker.cpusAvailable : parallelism, x64linux_compiler_list, 'Release', specialBranch, false,
false , testList, false, false, false, true, false, false, false, environmentList)}]
}
x64LinuxPostSteps = new Builder.PostSteps(
always: [{x64LinuxBuildScript.alwaysPostSteps(environmentList)}],
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, 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, environmentList)}]
}
x64MacBuildPostSteps = new Builder.PostSteps(
always: [{x64BuildScript.alwaysPostSteps(environmentList)}],
success: [{x64BuildScript.successPostSteps(scmVars, packagePush, environmentList)}])
}
// Define builders
x64LinuxBuilder = new Builder(buildSteps: x64LinuxBuildSteps, postSteps: x64LinuxPostSteps)
x64MacBuilder = new Builder(buildSteps: x64MacBuildSteps, postSteps: x64MacBuildPostSteps )
// 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)
if(!x64linux_compiler_list.isEmpty())
tasks[x64LinuxBuild.name] = build(x64LinuxBuild)
if(!mac_compiler_list.isEmpty())
tasks[x64MacBuild.name] = build(x64MacBuild)
cleanWs()
parallel tasks
if (build_scenario == 'Before merge to trunk')
gitNotify ("New CI: Merge to trunk", "Finish", 'SUCCESS')
}
}
}