forked from LiskArchive/lisk-nano
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
200 lines (183 loc) · 7.02 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
def get_build_info() {
pr_branch = ''
if (env.CHANGE_BRANCH != null) {
pr_branch = " (${env.CHANGE_BRANCH})"
}
build_info = "#${env.BUILD_NUMBER} of <${env.BUILD_URL}|${env.JOB_NAME}>${pr_branch}"
return build_info
}
def slack_send(color, message) {
/* Slack channel names are limited to 21 characters */
CHANNEL_MAX_LEN = 21
CHANNEL_SUFFIX = '-jenkins'
channel = "${env.JOB_NAME}".tokenize('/')[0]
channel_len = CHANNEL_MAX_LEN - CHANNEL_SUFFIX.size()
if ( channel.size() > channel_len ) {
channel = channel.substring(0, channel_len)
}
channel += CHANNEL_SUFFIX
echo "[slack_send] channel: ${channel} "
slackSend color: "${color}", message: "${message}", channel: "${channel}"
}
def fail(reason) {
build_info = get_build_info()
slack_send('danger', "Build ${build_info} failed (<${env.BUILD_URL}/console|console>, <${env.BUILD_URL}/changes|changes>)\nCause: ${reason}")
currentBuild.result = 'FAILURE'
error("${reason}")
}
/* comment out the next line to allow concurrent builds on the same branch */
properties([disableConcurrentBuilds(), pipelineTriggers([])])
node('lisk-nano') {
try {
stage ('Checkout and Start Lisk Core') {
try {
deleteDir()
checkout scm
} catch (err) {
echo "Error: ${err}"
fail('Stopping build: checkout failed')
}
try {
sh '''
N=${EXECUTOR_NUMBER:-0}; N=$((N+1))
cd ~/lisk-Linux-x86_64
# work around core bug: config.json gets overwritten; use backup
cp .config.json config_$N.json
# change core port, listen only on 127.0.0.1
sed -i -r -e "s/^(.*ort\\":) 4000,/\\1 400$N,/" config_$N.json
sed -i -r -e "s/^(.*\\"address\\":) \\"0.0.0.0\\",/\\1 \\"127.0.0.1\\",/" config_$N.json
# disable redis
sed -i -r -e "s/^(\\s*\\"cacheEnabled\\":) true/\\1 false/" config_$N.json
# change postgres databse
sed -i -r -e "s/^(\\s*\\"database\\": \\"lisk_test)\\",/\\1_$N\\",/" config_$N.json
cp etc/pm2-lisk.json etc/pm2-lisk_$N.json
sed -i -r -e "s/config.json/config_$N.json/" etc/pm2-lisk_$N.json
sed -i -r -e "s/(lisk.app)/\\1_$N/" etc/pm2-lisk_$N.json
# logs
sed -i -r -e "s/lisk.log/lisk_${JOB_BASE_NAME}_${BUILD_ID}.log/" config_$N.json
sed -i -r -e "s/lisk.app_$N/lisk.app_$N_${JOB_BASE_NAME}_${BUILD_ID}/" etc/pm2-lisk_$N.json
#
JENKINS_NODE_COOKIE=dontKillMe bash lisk.sh start_db -p etc/pm2-lisk_$N.json
bash lisk.sh rebuild -p etc/pm2-lisk_$N.json -f blockchain_explorer.db.gz
'''
} catch (err) {
echo "Error: ${err}"
fail('Stopping build: Lisk Core failed to start')
}
}
stage ('Install npm dependencies') {
try {
sh '''
cp -r ~/cache/development/node_modules ./ || true
npm install
./node_modules/protractor/bin/webdriver-manager update
'''
} catch (err) {
echo "Error: ${err}"
fail('Stopping build: npm install failed')
}
}
stage ('Run Eslint') {
try {
ansiColor('xterm') {
sh 'npm run --silent clean-build && npm run --silent copy-files && npm run --silent eslint'
}
} catch (err) {
echo "Error: ${err}"
fail('Stopping build: Eslint failed')
}
}
stage ('Build Nano') {
try {
sh '''
cp ~/.coveralls.yml-nano .coveralls.yml
npm run --silent build
'''
} catch (err) {
echo "Error: ${err}"
fail('Stopping build: nano build failed')
}
}
stage ('Deploy') {
try {
sh 'rsync -axl --delete --rsync-path="mkdir -p /var/www/test/${JOB_NAME%/*}/$BRANCH_NAME/ && rsync" $WORKSPACE/app/build/ jenkins@master-01:/var/www/test/${JOB_NAME%/*}/$BRANCH_NAME/'
githubNotify context: 'Jenkins test deployment', description: 'Commit was deployed to test', status: 'SUCCESS', targetUrl: "${HUDSON_URL}test/" + "${JOB_NAME}".tokenize('/')[0] + "/${BRANCH_NAME}"
} catch (err) {
echo "Error: ${err}"
fail('Stopping build: deploy failed')
}
}
stage ('Run Unit Tests') {
try {
ansiColor('xterm') {
sh '''
ON_JENKINS=true npm run --silent test
# Submit coverage to coveralls
cat coverage/*/lcov.info | coveralls -v
'''
}
} catch (err) {
echo "Error: ${err}"
fail('Stopping build: test suite failed')
}
}
stage ('Run E2E Tests') {
try {
ansiColor('xterm') {
withCredentials([string(credentialsId: 'lisk-nano-testnet-passphrase', variable: 'TESTNET_PASSPHRASE')]) {
sh '''
N=${EXECUTOR_NUMBER:-0}; N=$((N+1))
# End to End test configuration
export DISPLAY=:1$N
Xvfb :1$N -ac -screen 0 1280x1024x24 &
# Run end-to-end tests
if [ -z $CHANGE_BRANCH ]; then
npm run --silent e2e-test -- --params.baseURL file://$WORKSPACE/app/build/index.html --params.liskCoreURL https://testnet.lisk.io --cucumberOpts.tags @testnet --params.useTestnetPassphrase true
else
echo "Skipping @testnet end-to-end tests because we're not on 'development' branch"
fi
npm run --silent e2e-test -- --params.baseURL file://$WORKSPACE/app/build/index.html --params.liskCoreURL http://127.0.0.1:400$N
if [ -z $CHANGE_BRANCH ]; then
npm run --silent e2e-test -- --params.baseURL file://$WORKSPACE/app/build/index.html --cucumberOpts.tags @testnet --params.useTestnetPassphrase true --params.network testnet
else
echo "Skipping @testnet end-to-end tests because we're not on 'development' branch"
fi
'''
}
}
} catch (err) {
echo "Error: ${err}"
fail('Stopping build: end-to-end test suite failed')
}
}
} catch(err) {
echo "Error: ${err}"
} finally {
sh '''
N=${EXECUTOR_NUMBER:-0}; N=$((N+1))
curl --verbose http://127.0.0.1:400$N/api/blocks/getNethash || true
( cd ~/lisk-Linux-x86_64 && bash lisk.sh stop_node -p etc/pm2-lisk_$N.json ) || true
pgrep --list-full -f "Xvfb :1$N" || true
pkill --echo -f "Xvfb :1$N" -9 || echo "pkill returned code $?"
# cache nightly builds (development) only to save space
if [ $BRANCH_NAME = "development" ]; then
rsync -axl --delete $WORKSPACE/node_modules/ ~/cache/development/node_modules/ || true
fi
'''
dir('node_modules') {
deleteDir()
}
if (currentBuild.result == null || currentBuild.result == 'SUCCESS') {
/* delete all files on success */
deleteDir()
/* notify of success if previous build failed */
previous_build = currentBuild.getPreviousBuild()
if (previous_build != null && previous_build.result == 'FAILURE') {
build_info = get_build_info()
slack_send('good', "Recovery: build ${build_info} was successful.")
}
} else {
archiveArtifacts allowEmptyArchive: true, artifacts: 'e2e-test-screenshots/'
}
}
}