forked from hyperledger-iroha/iroha-dco
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
220 lines (208 loc) · 9.58 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
// Overall pipeline looks like the following
//
// |--Linux-----|----Debug
// | |----Release
// | OR
// |
//-- |--Linux ARM-|----Debug
// | |----Release
// | OR
// |
// |--MacOS-----|----Debug
// | |----Release
properties([parameters([
choice(choices: 'Debug\nRelease', description: '', name: 'BUILD_TYPE'),
booleanParam(defaultValue: true, description: '', name: 'Linux'),
booleanParam(defaultValue: false, description: '', name: 'ARM'),
booleanParam(defaultValue: false, description: '', name: 'MacOS'),
string(defaultValue: '4', description: 'How much parallelism should we exploit. "4" is optimal for machines with modest amount of memory and at least 4 cores', name: 'PARALLELISM')]),
pipelineTriggers([cron('@weekly')])])
pipeline {
environment {
CCACHE_DIR = '/opt/.ccache'
SORABOT_TOKEN = credentials('SORABOT_TOKEN')
SONAR_TOKEN = credentials('SONAR_TOKEN')
CODECOV_TOKEN = credentials('CODECOV_TOKEN')
DOCKERHUB = credentials('DOCKERHUB')
DOCKER_IMAGE = 'hyperledger/iroha-docker-develop:v1'
IROHA_NETWORK = "iroha-${GIT_COMMIT}-${BUILD_NUMBER}"
IROHA_POSTGRES_HOST = "pg-${GIT_COMMIT}-${BUILD_NUMBER}"
IROHA_POSTGRES_USER = "pg-user-${GIT_COMMIT}"
IROHA_POSTGRES_PASSWORD = "${GIT_COMMIT}"
IROHA_POSTGRES_PORT = 5432
CTEST_OUTPUT_ON_FAILURE = 1
}
agent {
label 'docker_1'
}
stages {
stage('Build Debug') {
when { expression { params.BUILD_TYPE == 'Debug' } }
parallel {
stage ('Linux') {
when { expression { return params.Linux } }
steps {
script {
def doxygen = load ".jenkinsci/doxygen.groovy"
def dockerize = load ".jenkinsci/dockerize.groovy"
sh "docker network create ${env.IROHA_NETWORK}"
def p_c = docker.image('postgres:9.5').run(""
+ " -e POSTGRES_USER=${env.IROHA_POSTGRES_USER}"
+ " -e POSTGRES_PASSWORD=${env.IROHA_POSTGRES_PASSWORD}"
+ " --name ${env.IROHA_POSTGRES_HOST}"
+ " --network=${env.IROHA_NETWORK}")
docker.image("${env.DOCKER_IMAGE}").inside(""
+ " -e IROHA_POSTGRES_HOST=${env.IROHA_POSTGRES_HOST}"
+ " -e IROHA_POSTGRES_PORT=${env.IROHA_POSTGRES_PORT}"
+ " -e IROHA_POSTGRES_USER=${env.IROHA_POSTGRES_USER}"
+ " -e IROHA_POSTGRES_PASSWORD=${env.IROHA_POSTGRES_PASSWORD}"
+ " --network=${env.IROHA_NETWORK}"
+ " -v /var/jenkins/ccache:${CCACHE_DIR}") {
def scmVars = checkout scm
env.IROHA_VERSION = "0x${scmVars.GIT_COMMIT}"
env.IROHA_HOME = "/opt/iroha"
env.IROHA_BUILD = "/opt/iroha/build"
env.IROHA_RELEASE = "${env.IROHA_HOME}/docker/release"
sh """
ccache --version
ccache --show-stats
ccache --zero-stats
ccache --max-size=1G
"""
sh """
cmake \
-DCOVERAGE=ON \
-DTESTING=ON \
-H. \
-Bbuild \
-DCMAKE_BUILD_TYPE=${params.BUILD_TYPE} \
-DIROHA_VERSION=${env.IROHA_VERSION}
"""
sh "cmake --build build -- -j${params.PARALLELISM}"
sh "ccache --cleanup"
sh "ccache --show-stats"
sh "cmake --build build --target test"
sh "cmake --build build --target gcovr"
sh "cmake --build build --target cppcheck"
if ( env.BRANCH_NAME == "master" ||
env.BRANCH_NAME == "develop" ) {
dockerize.doDockerize()
doxygen.doDoxygen()
}
// Codecov
sh "bash <(curl -s https://codecov.io/bash) -f build/reports/gcovr.xml -t ${CODECOV_TOKEN} || echo 'Codecov did not collect coverage reports'"
// Sonar
if (env.CHANGE_ID != null) {
sh """
sonar-scanner \
-Dsonar.github.disableInlineComments \
-Dsonar.github.repository='hyperledger/iroha' \
-Dsonar.analysis.mode=preview \
-Dsonar.login=${SONAR_TOKEN} \
-Dsonar.projectVersion=${BUILD_TAG} \
-Dsonar.github.oauth=${SORABOT_TOKEN} \
-Dsonar.github.pullRequest=${CHANGE_ID}
"""
}
//stash(allowEmpty: true, includes: 'build/compile_commands.json', name: 'Compile commands')
//stash(allowEmpty: true, includes: 'build/reports/', name: 'Reports')
//archive(includes: 'build/bin/,compile_commands.json')
}
}
}
}
stage('ARM') {
when { expression { return params.ARM } }
steps {
sh "echo ARM build will be running there"
}
}
stage('MacOS'){
when { expression { return params.MacOS } }
steps {
sh "MacOS build will be running there"
}
}
}
}
stage('Build Release') {
when { expression { params.BUILD_TYPE == 'Release' } }
parallel {
stage('Linux') {
when { expression { return params.Linux } }
steps {
script {
def scmVars = checkout scm
env.IROHA_VERSION = "0x${scmVars.GIT_COMMIT}"
}
sh """
ccache --version
ccache --show-stats
ccache --zero-stats
ccache --max-size=1G
"""
sh """
cmake \
-DCOVERAGE=OFF \
-DTESTING=OFF \
-H. \
-Bbuild \
-DCMAKE_BUILD_TYPE=${params.BUILD_TYPE} \
-DPACKAGE_DEB=ON \
-DPACKAGE_TGZ=ON \
-DIROHA_VERSION=${IROHA_VERSION}
"""
sh "cmake --build build -- -j${params.PARALLELISM}"
sh "ccache --cleanup"
sh "ccache --show-stats"
sh """
mv build/iroha-{*,linux}.deb && mv build/iroha-{*,linux}.tar.gz
echo ${IROHA_VERSION} > version.txt
"""
archive(includes: 'build/iroha-linux.deb,build/iroha-linux.tar.gz,build/version.txt')
}
}
stage('ARM') {
when { expression { return params.ARM } }
steps {
sh "echo ARM build will be running there"
}
}
stage('MacOS') {
when { expression { return params.MacOS } }
steps {
sh "MacOS build will be running there"
}
}
}
}
stage('SonarQube') {
when { expression { params.BUILD_TYPE == 'Release' } }
steps {
sh """
if [ -n ${SONAR_TOKEN} ] && \
[ -n ${BUILD_TAG} ] && \
[ -n ${BRANCH_NAME} ]; then
sonar-scanner \
-Dsonar.login=${SONAR_TOKEN} \
-Dsonar.projectVersion=${BUILD_TAG} \
-Dsonar.branch=${BRANCH_NAME}
else
echo 'required env vars not found'
fi
"""
}
}
}
post {
always {
script {
sh """
docker stop $IROHA_POSTGRES_HOST
docker rm $IROHA_POSTGRES_HOST
docker network rm $IROHA_NETWORK
"""
}
}
}
}