-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathJenkinsfile
294 lines (262 loc) · 9.42 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
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
#!groovy
import com.cwctravel.hudson.plugins.extended_choice_parameter.ExtendedChoiceParameterDefinition
////////////////////////////////////////
properties([parameters([booleanParam(defaultValue: false, description: 'Build in debug mode', name: 'Debug'),
checkBox("Network", "Mainnet,Testnet,Customnet", "Mainnet" /*default*/, 0, "PT_SINGLE_SELECT", "Select network"),
string(defaultValue: "", description: 'Custom genesis URL(Valid only for \"Customnet\" Network)', name: 'GenesisURL'),
string(defaultValue: "", description: 'Package name(Valid only for \"Customnet\" Network)', name: 'PackageName'),
checkBox("Package", "sophiatx,light-client,cli-wallet", "sophiatx,light-client,cli-wallet" /*default*/, 0, "PT_CHECKBOX", "Select packages to be built")
])
])
pipeline {
options {
buildDiscarder(logRotator(artifactNumToKeepStr: '5'))
skipDefaultCheckout()
parallelsAlwaysFailFast()
}
environment {
GENESIS_FILE = ""
BUILD_TESTNET = ""
BUILD_TYPE = ""
INSTALL_PREFIX="install"
}
agent any
stages {
stage('Init build variables') {
steps {
init()
}
}
stage('Git Checkout') {
steps {
checkout scm
}
}
stage('Build') {
steps {
start_build()
}
}
stage('Tests') {
steps {
tests()
}
}
stage('Package') {
steps {
create_packages()
}
}
stage('Archive') {
environment {
LIB_ARCHIVE_NAME = "libalexandria_" + "${env.NODE_NAME}" + ".tar.gz"
ARCHIVE_NAME = "sophiatx_" + "${env.NODE_NAME}" +"_#" + "${env.BUILD_NUMBER}" + ".tar.gz"
PLUGIN_ARCHIVE_NAME = "plugins_" + "${env.NODE_NAME}" +"_#" + "${env.BUILD_NUMBER}" + ".tar.gz"
}
steps {
run_archive()
}
}
stage('Clean WS') {
steps {
cleanWs()
}
}
}
}
////////////////////////////////////////
def init() {
if( params.Debug ) {
BUILD_TYPE = "Debug"
} else {
BUILD_TYPE = "Release"
}
if( params.Network == "Mainnet" ) {
BUILD_TESTNET = "false"
GENESIS_FILE = "${WORKSPACE}/libraries/egenesis/genesis.json"
} else if( params.Network == "Testnet" ) {
BUILD_TESTNET = "true"
GENESIS_FILE = "${WORKSPACE}/libraries/egenesis/genesis_testnet.json"
} else if( params.Network == "Customnet" ) {
BUILD_TESTNET = "false"
if (params.GenesisURL == "") {
error("Genesis URL must be provided to build Custom network...")
}
GENESIS_FILE = "${WORKSPACE}/libraries/egenesis/custom_genesis.json"
try {
sh "rm -f ${GENESIS_FILE}"
} catch(Exception e) {
echo "Skipping removing existing(previous) custom genesis file. It does not exist."
}
try {
sh "wget --output-document=${GENESIS_FILE} ${params.GenesisURL}"
} catch(Exception e) {
error("Failed to download genesis file from URL: ${params.GenesisURL}. Valid genesis URL must be provided for Custom networks!")
}
} else {
error("Invalid \"Network\" option selected...")
}
}
def start_build() {
sh "cmake . -DUSE_PCH=OFF \
-DZLIB_ROOT=${ZLIB} \
-DBOOST_ROOT=${BOOST_167} \
-DOPENSSL_ROOT_DIR=${OPENSSL_111} \
-DSQLITE3_ROOT_DIR=${SQLITE_3253} \
-DSOPHIATX_STATIC_BUILD=ON \
-DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
-DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} \
-DSOPHIATX_EGENESIS_JSON=${GENESIS_FILE} \
-DBUILD_SOPHIATX_TESTNET=${BUILD_TESTNET} \
-DAPP_INSTALL_DIR=${INSTALL_PREFIX}/bin/ \
-DCONF_INSTALL_DIR=${INSTALL_PREFIX}/etc \
-DSERVICE_INSTALL_DIR=${INSTALL_PREFIX}/lib"
sh 'make install -j4'
}
def tests() {
script {
if( BUILD_TESTNET == "false" ) {
sh './tests/chain_test'
sh './tests/plugin_test'
//sh './tests/smart_contracts/smart_contracts_tests'
sh './tests/utilities/utilities_tests'
sh './libraries/fc/vendor/secp256k1-zkp/src/project_secp256k1-build/tests'
sh './libraries/fc/tests/all_tests'
//sh './libraries/SQLiteCpp/SQLiteCpp_tests'
}
}
}
def run_archive() {
dir('install') {
dir('lib') {
script {
echo "${LIB_ARCHIVE_NAME}"
if( !params.Debug ) {
try {
sh 'strip -s libalexandria.so libalexandriaJNI.so *_plugin.so' //strip symbols
} catch(Exception e) {
echo "Skipping strip"
}
}
}
sh "tar -czf ${LIB_ARCHIVE_NAME} libalexandria.so libalexandriaJNI.so alexandria.hpp AlexandriaJNI.java" //create tar file
sh "tar -czf ${PLUGIN_ARCHIVE_NAME} *_plugin.[^a]*" //create tar file
archiveArtifacts '*.gz'
}
dir('bin') {
sh 'rm -f test*' //remove test binaries
script {
echo "${ARCHIVE_NAME}"
if( !params.Debug ) {
try {
sh 'strip -s *' //strip symbols
} catch(Exception e) {
echo "Skipping strip"
}
}
if( BUILD_TESTNET == "true" ) {
sh "cp ${WORKSPACE}/contrib/testnet_config.ini ."//copy config
sh "tar -czf ${ARCHIVE_NAME} sophiatx_cli_wallet sophiatxd sophiatxd_light testnet_config.ini" //create tar file
} else {
sh "cp ${WORKSPACE}/contrib/fullnode_config.ini ."//copy configs
sh "cp ${WORKSPACE}/contrib/witness_config.ini ."//copy configs
sh "tar -czf ${ARCHIVE_NAME} sophiatx_cli_wallet sophiatxd sophiatxd_light fullnode_config.ini witness_config.ini/" //create tar file
}
}
archiveArtifacts '*.gz'
}
}
}
def create_packages() {
if (!params.Package) {
return
}
if (params.Package.contains("sophiatx")) {
build_jenkins_package("programs/sophiatxd", "sophiatx-testnet")
}
if (params.Package.contains("light-client")) {
build_jenkins_package("programs/sophiatxd_light", "sophiatx-light-client")
}
if (params.Package.contains("cli-wallet")) {
build_jenkins_package("programs/cli_wallet", "sophiatx-cli-wallet")
}
}
def build_jenkins_package(String dirPath, String testPackageName) {
dir(dirPath) {
dir("jenkins_package") {
// all Copy configuration files from package directory except "rules"
sh "cp -n -r ../package/debian/* debian/"
if( params.Network == "Testnet" ) {
sh """sed -i -r 's/[0-9]+\\.[0-9]+\\.[0-9]+/0.0.'"${env.BUILD_NUMBER}"'/g' debian/changelog"""
}
sh "debuild --set-envvar INSTALL_DIR_ENV=${WORKSPACE}/${INSTALL_PREFIX} \
--set-envvar SRC_ROOT_DIR_ENV=${WORKSPACE} \
-uc -us"
}
if( params.Network == "Testnet" ) {
packageName = testPackageName + "_#${env.BUILD_NUMBER}.deb"
sh "mv *.deb ${packageName}"
} else if( params.Network == "Customnet" ) {
if (params.PackageName == "") {
error("PackageName must be provided when creating \"Customnet\" package!")
}
sh "mv *.deb ${params.PackageName}"
}
archiveArtifacts '*.deb'
}
}
def build_package(String dirPath) {
// If there is existing cmakecache from previous build, delete it as we want
if (fileExists('CMakeCache.txt') == true) {
sh "rm -f CMakeCache.txt"
}
dir(dirPath) {
dir("package") {
sh "debuild --set-envvar CMAKE_BUILD_TYPE_ENV=${BUILD_TYPE} \
--set-envvar BUILD_SOPHIATX_TESTNET_ENV=${BUILD_TESTNET} \
--set-envvar SOPHIATX_EGENESIS_JSON_ENV=${GENESIS_FILE} \
--set-envvar OPENSSL_ROOT_DIR_ENV=${OPENSSL_111} \
--set-envvar BOOST_ROOT_DIR_ENV=${BOOST_167} \
-uc -us"
}
archiveArtifacts '*.deb'
}
}
def checkBox (String name, String values, String defaultValue,
int visibleItemCnt=0, String type, String description='', String delimiter=',') {
// default same as number of values
visibleItemCnt = visibleItemCnt ?: values.split(',').size()
return new ExtendedChoiceParameterDefinition(
name, //name,
type, //type
values, //value
"", //projectName
"", //propertyFile
"", //groovyScript
"", //groovyScriptFile
"", //bindings
"", //groovyClasspath
"", //propertyKey
defaultValue, //defaultValue
"", //defaultPropertyFile
"", //defaultGroovyScript
"", //defaultGroovyScriptFile
"", //defaultBindings
"", //defaultGroovyClasspath
"", //defaultPropertyKey
"", //descriptionPropertyValue
"", //descriptionPropertyFile
"", //descriptionGroovyScript
"", //descriptionGroovyScriptFile
"", //descriptionBindings
"", //descriptionGroovyClasspath
"", //descriptionPropertyKey
"", //javascriptFile
"", //javascript
false, //saveJSONParameterToFile
false, //quoteValue
visibleItemCnt, //visibleItemCount
description, //description
delimiter //multiSelectDelimiter
)
}