forked from hyperledger/indy-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile.cd
187 lines (161 loc) · 6.29 KB
/
Jenkinsfile.cd
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
#!groovy
@Library('SovrinHelpers') _
def name = 'indy-node'
def nodeTestUbuntu = {
try {
echo 'Ubuntu Test: Checkout csm'
checkout scm
echo 'Ubuntu Test: Build docker image'
def testEnv = dockerHelpers.build(name)
testEnv.inside('--network host') {
echo 'Ubuntu Test: Install dependencies'
testHelpers.install()
echo 'Ubuntu Test: Test'
testHelpers.testRunner([resFile: "test-result-node.${NODE_NAME}.txt", testDir: 'indy_node'])
//testHelpers.testJUnit(resFile: "test-result-node.${NODE_NAME}.xml")
}
}
finally {
echo 'Ubuntu Test: Cleanup'
step([$class: 'WsCleanup'])
}
}
def commonTestUbuntu = {
try {
echo 'Ubuntu Test: Checkout csm'
checkout scm
echo 'Ubuntu Test: Build docker image'
def testEnv = dockerHelpers.build(name)
testEnv.inside {
echo 'Ubuntu Test: Install dependencies'
testHelpers.install()
echo 'Ubuntu Test: Test'
testHelpers.testJUnit([resFile: "test-result-common.${NODE_NAME}.xml", testDir: 'indy_common'])
}
}
finally {
echo 'Ubuntu Test: Cleanup'
step([$class: 'WsCleanup'])
}
}
def buildDebUbuntu = { repoName, releaseVersion, sourcePath ->
def volumeName = "$name-deb-u1604"
if (env.BRANCH_NAME != '' && env.BRANCH_NAME != 'master') {
volumeName = "${volumeName}.${BRANCH_NAME}"
}
if (sh(script: "docker volume ls -q | grep -q '^$volumeName\$'", returnStatus: true) == 0) {
sh "docker volume rm $volumeName"
}
dir('build-scripts/ubuntu-1604') {
sh "./build-$name-docker.sh \"$sourcePath\" $releaseVersion $volumeName"
sh "./build-3rd-parties-docker.sh $volumeName"
}
return "$volumeName"
}
def systemTests = { component ->
node("ubuntu") {
checkout scm
try {
dir("environment/docker/pool"){
stage("Patch core dockerfile") {
sh """
sed -i 's/repo.sovrin.org\\/deb xenial .*\\+"/repo.sovrin.org\\/deb xenial $component"/g' core.ubuntu.dockerfile
sed -i 's/sdk\\/deb xenial .\\+"/sdk\\/deb xenial stable"/g' core.ubuntu.dockerfile
sed -i 's/\\(RUN pip3 install python3-indy\\)/& pytest/g' core.ubuntu.dockerfile
"""
}
stage("Run pool") {
echo "System Tests ($component): Running nodes..."
sh './pool_start.sh 25'
pool_nodes = sh(script: 'docker ps', returnStdout: true)
echo "System Tests ($component): pool_nodes"
}
stage("Prepare and run client") {
sh '''
sed -i 's/\\(docker exec -it\\)/#&/g' client_start.sh'
./client_for_pool_start.sh
'''
}
}
stage("Prepare tests") {
testHelpers.getSystemTests(targetDir: './system_tests')
sh '''
docker cp ./system_tests/system indyclient:/home/indy
docker exec -t --user indy indyclient cp /var/lib/indy/sandbox/pool_transactions_genesis /home/indy/system
'''
}
String testReportFileName = "system_tests_report.xml"
try {
stage("Run tests") {
dir("environment/docker/pool"){
sh """
docker exec -t --user indy indyclient bash -c "cd /home/indy/system && pytest --junit-xml=./reports/$testReportFileName test_ledger.py"
"""
}
}
} finally {
stage("Upload test teports") {
sh "mkdir -p system_tests/reports"
dir("system_tests/reports"){
sh "docker cp indyclient:/home/indy/system/reports/$testReportFileName ./"
archiveArtifacts artifacts: testReportFileName, allowEmptyArchive: true
junit testReportFileName
}
}
}
} catch (Exception exc) {
echo "System Tests ($component): Catch the exception ${exc.getMessage()}"
echo "System Tests ($component): Stack trace:"
echo "{exc.getStackTrace()}"
} finally {
stage('Cleanup') {
cleanWs()
// TODO harden
try {
sh "./client_stop.sh"
} catch (Exception ex) {
echo "System Tests ($component): client container stop error: ${exc.getMessage()}"
}
try {
sh "./pool_stop.sh"
} catch (Exception ex) {
echo "System Tests ($component): client container stop error: ${exc.getMessage()}"
}
sh """
docker container prune -f
docker network prune -f
"""
}
}
}
}
options = new TestAndPublishOptions()
// FIXME: Remove after tests
env.BRANCH_NAME = 'master'
options.skip([
StagesEnum.IS_TESTED,
StagesEnum.STATIC_CODE_VALIDATION,
StagesEnum.TEST,
StagesEnum.AUTOMERGE,
StagesEnum.GET_RELEASE_VERSION,
StagesEnum.PYPI_RELEASE,
StagesEnum.PACK_RELEASE,
StagesEnum.PACK_RELEASE_COPY,
StagesEnum.GITHUB_RELEASE,
StagesEnum.QA_NOTIF,
StagesEnum.QA_APPROVAL,
StagesEnum.PRODUCT_NOTIF,
StagesEnum.PRODUCT_APPROVAL,
StagesEnum.TGB_NOTIF,
StagesEnum.TGB_APPROVAL,
StagesEnum.PACK_RELEASE_ST,
StagesEnum.PACK_RELEASE_COPY_ST,
StagesEnum.GITHUB_RELEASE_ST,
StagesEnum.POOL_UPDATE_NOTIF,
StagesEnum.BUILD_RESULT_NOTIF,
])
//options.enable([StagesEnum.PACK_RELEASE_COPY, StagesEnum.PACK_RELEASE_COPY_ST])
options.setCopyWithDeps(true)
options.setSystemTestsCb(systemTests)
options.setPrContexts([env.INDY_GITHUB_PR_REQUIRED_CONTEXT ?: "ci/hyperledger-jenkins/pr-merge"])
testAndPublish(name, [ubuntu: [node: nodeTestUbuntu, common: commonTestUbuntu]], true, options, [ubuntu: buildDebUbuntu])