forked from hyperledger/indy-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile.ci
211 lines (181 loc) · 5.47 KB
/
Jenkinsfile.ci
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
#!/usr/bin/env groovy
/*
* This Jenkinsfile is intended to run on https://ci.evernym.com and may fail anywhere else.
*
* Environment requirements:
* - environment variable:
* - INDY_AGENT_LINUX_LABEL: label for linux agent
* - (optional) INDY_AGENT_WINDOWS_LABEL: label for windows agent
* - agents:
* - linux:
* - docker
* - windows:
* - python3.5 + virtualenv
* - cygwin
*/
name = 'indy-node'
def config = [
codeValidation: true,
runTests: true,
failFast: false,
sendNotif: true
]
env.INDY_AGENT_LINUX_LABEL = env.INDY_AGENT_LINUX_LABEL || 'linux'
def labels = [env.INDY_AGENT_LINUX_LABEL] // TODO enable windows
if (env.INDY_AGENT_WINDOWS_LABEL) {
labels += env.INDY_AGENT_WINDOWS_LABEL
}
def buildDocker(imageName, dockerfile) {
def uid = sh(returnStdout: true, script: 'id -u').trim()
return docker.build("$imageName", "--build-arg uid=$uid -f $dockerfile")
}
def install(options=[:]) {
options.pip = options.pip ?: 'pip'
options.isVEnv = options.isVEnv ?: false
options.deps = options.deps ?: []
for (def dep : options.deps) {
sh "$options.pip install " + (options.isVEnv ? "-U" : "") + " $dep"
}
sh "$options.pip install " + (options.isVEnv ? "--ignore-installed" : "") + " pytest"
sh "$options.pip install ."
}
def withTestEnv(body) {
echo 'Test: Checkout csm'
checkout scm
if (isUnix()) {
echo 'Test: Build docker image'
buildDocker("$name-test", "ci/ubuntu.dockerfile ci").inside {
echo 'Test: Install dependencies'
install()
body.call('python')
}
} else { // windows expected
echo 'Test: Build virtualenv'
def virtualEnvDir = ".venv"
sh "virtualenv --system-site-packages $virtualEnvDir"
echo 'Test: Install dependencies'
install(pip: "$virtualEnvDir/Scripts/pip", isVenv: true)
body.call("$virtualEnvDir/Scripts/python")
}
}
def test(options=[:]) {
options.resFile = options.resFile ?: 'test-result.txt'
options.testDir = options.testDir ?: '.'
options.python = options.python ?: 'python'
options.useRunner = options.useRunner ?: false
options.testOnlySlice = options.testOnlySlice ?: '1/1'
try {
if (options.useRunner) {
sh "PYTHONASYNCIODEBUG='0' $options.python runner.py --pytest \"$options.python -m pytest\" --dir $options.testDir --output \"$options.resFile\" --test-only-slice \"$options.testOnlySlice\""
} else {
sh "$options.python -m pytest --junitxml=$options.resFile $options.testDir"
}
}
finally {
try {
sh "ls -la $options.resFile"
} catch (Exception ex) {
// pass
}
if (options.useRunner) {
archiveArtifacts allowEmptyArchive: true, artifacts: "$options.resFile"
} else {
junit "$options.resFile"
}
}
}
def staticCodeValidation() {
try {
echo 'Static code validation'
checkout scm
buildDocker('code-validation', 'ci/code-validation.dockerfile ci').inside {
sh "python3 -m flake8"
}
}
finally {
echo 'Static code validation: Cleanup'
step([$class: 'WsCleanup'])
}
}
def tests = [
common: { python ->
test(
resFile: "test-result-common.${NODE_NAME}.xml",
testDir: 'sovrin_common',
python: python
)
},
client: { python ->
test(
resFile: "test-result-client.${NODE_NAME}.txt",
testDir: 'sovrin_client',
python: python,
useRunner: true
)
},
node: { python ->
test(
resFile: "test-result-node.${NODE_NAME}.txt",
testDir: 'sovrin_node',
python: python,
useRunner: true
)
},
].collect {k, v -> [k, v]}
def builds = [:]
for (i = 0; i < labels.size(); i++) {
def label = labels[i]
def descr = "${label}Test"
for(j = 0; j < tests.size(); j++) {
def part = tests[j][0]
def testFn = tests[j][1]
def currDescr = "${descr}-${part}"
builds[(currDescr)] = {
stage(currDescr) {
node(label) {
try {
withTestEnv() { python ->
echo 'Test'
testFn(python)
}
}
finally {
echo 'Cleanup'
step([$class: 'WsCleanup'])
}
}
}
}
}
}
// PIPELINE
try {
stage('Static code validation') {
if (config.codeValidation) {
node(env.INDY_AGENT_LINUX_LABEL) {
staticCodeValidation()
}
}
}
stage('Build / Test') {
if (config.runTests) {
builds.failFast = config.failFast
parallel builds
}
}
currentBuild.result = 'SUCCESS'
} catch (Exception err) {
currentBuild.result = 'FAILURE'
} finally {
stage('Build result notification') {
if (config.sendNotif) {
def emailMessage = [
body: '$DEFAULT_CONTENT',
replyTo: '$DEFAULT_REPLYTO',
subject: '$DEFAULT_SUBJECT',
recipientProviders: [[$class: 'DevelopersRecipientProvider'], [$class: 'RequesterRecipientProvider']]
]
emailext emailMessage
}
}
}