/
Jenkinsfile
143 lines (137 loc) · 3.22 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
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 = "${env.JOB_NAME}".tokenize('/')[0]
channel = channel.replace('lisk-', 'lisk-ci-')
if ( channel.size() > CHANNEL_MAX_LEN ) {
channel = channel.substring(0, CHANNEL_MAX_LEN)
}
echo "[slack_send] channel: ${channel} "
slackSend color: "${color}", message: "${message}", channel: "${channel}"
}
pipeline {
agent { node { label 'lisk-explorer' } }
environment {
LISK_VERSION = '0.9.12a'
//
EXPLORER_PORT = "604$EXECUTOR_NUMBER"
LISK_HOST = 'localhost'
REDIS_DB = "$EXECUTOR_NUMBER"
REDIS_HOST = 'localhost'
}
stages {
stage ('Build dependencies') {
steps {
sh 'npm install'
}
}
stage ('Run ESLint') {
steps {
sh 'npm run eslint'
}
}
stage ('Build bundles') {
steps {
sh 'npm run build'
}
}
stage ('Build candles') {
steps {
// marketwatcher needs to be enabled to builds candles
sh '''
cp test/config.test ./config.js
grunt candles:build
'''
}
}
stage ('Start Lisk') {
steps {
dir("$WORKSPACE/$BRANCH_NAME/") {
ansiColor('xterm') {
sh '''
rsync -axl --delete ~/lisk-docker/examples/development/ ./
cp ~/blockchain_explorer.db.gz ./blockchain.db.gz
make coldstart
'''
// show some build-related info
sh '''
sha1sum ./blockchain.db.gz
docker-compose config
docker-compose ps
'''
// temp.
sh '''
docker-compose exec -T lisk sed -i -r -e 's/(\\s*"topAccounts":)\\s*false,/\\1 true,/' config.json
docker-compose restart lisk
'''
}
}
}
}
stage ('Start Explorer') {
steps {
sh '''
cd $WORKSPACE/$BRANCH_NAME
LISK_PORT=$( docker-compose port lisk 4000 |cut -d ":" -f 2 )
cd -
LISK_PORT=$LISK_PORT node app.js -p $EXPLORER_PORT &>/dev/null &
sleep 20
'''
}
}
stage ('Run API tests') {
steps {
sh '''
sed -i -r -e "s/6040/$EXPLORER_PORT/" test/node.js
npm run test
'''
}
}
stage ('Run E2E tests') {
steps {
wrap([$class: 'Xvfb']) {
sh '''
npm run e2e -- --params.baseURL http://localhost:$EXPLORER_PORT
'''
}
}
}
}
post {
success {
script {
if (currentBuild.result == null || currentBuild.result == 'SUCCESS') {
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.")
}
}
}
}
failure {
script {
build_info = get_build_info()
slack_send('danger', "Build ${build_info} failed (<${env.BUILD_URL}/console|console>, <${env.BUILD_URL}/changes|changes>)\n")
}
}
always {
dir("$WORKSPACE/$BRANCH_NAME/") {
ansiColor('xterm') {
sh 'docker-compose logs || true'
sh 'make mrproper'
}
}
junit 'xunit-report.xml'
archiveArtifacts artifacts: 'logs/*.log', allowEmptyArchive: true
}
}
}