-
Notifications
You must be signed in to change notification settings - Fork 2
/
Jenkinsfile
337 lines (337 loc) · 13 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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
pipeline {
options {
skipDefaultCheckout()
buildDiscarder(logRotator(numToKeepStr: '10', artifactNumToKeepStr: '10'))
preserveStashes()
}
agent none
parameters {
choice choices: ['', 'All', 'Any', 'Linux', 'Windows', 'Docker'], description: 'Build Agent', name: 'BUILD_AGENT_FILTER'
choice choices: ['', 'All', 'Debug and Release', 'Debug', 'Release', 'MinSizeRel', 'RelWithDebInfo'], description: 'Build Type', name: 'BUILD_TYPE_FILTER'
booleanParam defaultValue: true, description: 'Enable Deploy Stage', name: 'ENABLE_DEPLOY_STAGE'
}
stages {
stage('Init') {
steps {
script {
def BUILD_AGENT_FILTER = ''
def BUILD_TYPE_FILTER = ''
if (params.BUILD_AGENT_FILTER == '' || params.BUILD_TYPE_FILTER == '') {
def inputParams = input (
message: 'Set Parameters:',
parameters: [
choice(choices: ['All', 'Any', 'Linux', 'Windows', 'Docker'], description: 'Build Agent', name: 'BUILD_AGENT_FILTER'),
choice(choices: ['All', 'Debug and Release', 'Debug', 'Release', 'MinSizeRel', 'RelWithDebInfo'], description: 'Build Type', name: 'BUILD_TYPE_FILTER')
]
)
BUILD_AGENT_FILTER = inputParams.BUILD_AGENT_FILTER
BUILD_TYPE_FILTER = inputParams.BUILD_TYPE_FILTER
} else {
BUILD_AGENT_FILTER = params.BUILD_AGENT_FILTER
BUILD_TYPE_FILTER = params.BUILD_TYPE_FILTER
}
env.BUILD_AGENT_FILTER = BUILD_AGENT_FILTER
env.BUILD_TYPE_FILTER = BUILD_TYPE_FILTER
parallel (
"${BUILD_AGENT_FILTER} - ${BUILD_TYPE_FILTER}": {
stage('Set Parameters') {
echo "Build Agent: ${BUILD_AGENT_FILTER}"
echo "Build Type: ${BUILD_TYPE_FILTER}"
}
}
)
}
}
}
stage('Pipeline') {
matrix {
when {
allOf {
anyOf {
expression { env.BUILD_AGENT_FILTER == 'All' }
expression { env.BUILD_AGENT_FILTER == env.BUILD_AGENT }
}
anyOf {
expression { env.BUILD_TYPE_FILTER == 'All' }
expression { env.BUILD_TYPE_FILTER == env.BUILD_TYPE }
allOf {
expression { env.BUILD_TYPE_FILTER == 'Debug and Release' }
anyOf {
expression { env.BUILD_TYPE == 'Debug' }
expression { env.BUILD_TYPE == 'Release' }
}
}
}
not {
allOf {
expression { env.BUILD_AGENT_FILTER == 'All' }
expression { env.BUILD_AGENT == 'Any' }
}
}
}
}
axes {
axis {
name 'BUILD_AGENT'
values 'Any', 'Linux', 'Windows', 'Docker'
}
axis {
name 'BUILD_TYPE'
values 'Debug', 'Release', 'MinSizeRel', 'RelWithDebInfo'
}
}
stages {
stage('Check') {
options {
timeout(time: 5, unit: 'SECONDS')
}
agent {
node {
label env.BUILD_AGENT == 'Any' ? '' : env.BUILD_AGENT
customWorkspace "${env.JOB_NAME}/${env.BUILD_AGENT}/${env.BUILD_TYPE}"
}
}
steps {
echo "Build Agent: ${env.BUILD_AGENT}"
echo "Build Type: ${env.BUILD_TYPE}"
echo "Build Workspace: ${env.JOB_NAME}/${env.BUILD_AGENT}/${env.BUILD_TYPE}"
}
}
stage('Prepare') {
agent {
node {
label env.BUILD_AGENT == 'Any' ? '' : env.BUILD_AGENT
customWorkspace "${env.JOB_NAME}/${env.BUILD_AGENT}/${env.BUILD_TYPE}"
}
}
steps {
checkout scm
script {
if (isUnix()) {
sh '''make venv_create
`make --no-print-directory venv_activate`
python -m pip install --upgrade pip'''
} else {
bat 'make venv_create && .venv\\Scripts\\activate && python -m pip install --upgrade pip'
}
}
stash "prepare_${env.BUILD_AGENT}_${env.BUILD_TYPE}"
}
}
stage('Build') {
agent {
node {
label env.BUILD_AGENT == 'Any' ? '' : env.BUILD_AGENT
customWorkspace "${env.JOB_NAME}/${env.BUILD_AGENT}/${env.BUILD_TYPE}"
}
}
steps {
unstash "prepare_${env.BUILD_AGENT}_${env.BUILD_TYPE}"
script {
if (isUnix()) {
sh '''`make --no-print-directory venv_activate`
make cmake_project
make build'''
} else {
bat 'make venv_activate && make cmake_project && make build'
}
}
stash "build_${env.BUILD_AGENT}_${env.BUILD_TYPE}"
}
}
stage('Test') {
environment {
GTEST_OUTPUT = 'xml:../gtest/'
}
agent {
node {
label env.BUILD_AGENT == 'Any' ? '' : env.BUILD_AGENT
customWorkspace "${env.JOB_NAME}/${env.BUILD_AGENT}/${env.BUILD_TYPE}"
}
}
steps {
unstash "build_${env.BUILD_AGENT}_${env.BUILD_TYPE}"
script {
if (isUnix()) {
sh "cd ${env.BUILD_TYPE} && ctest -C ${env.BUILD_TYPE} -T Test --no-compress-output"
} else {
bat "cd ${env.BUILD_TYPE} && ctest -C ${env.BUILD_TYPE} -T Test --no-compress-output"
}
}
stash "test_${env.BUILD_AGENT}_${env.BUILD_TYPE}"
}
post {
always {
script {
if (isUnix()) {
sh "mv ${env.BUILD_TYPE} ${env.BUILD_AGENT}_${env.BUILD_TYPE}"
} else {
bat "rename ${env.BUILD_TYPE} ${env.BUILD_AGENT}_${env.BUILD_TYPE}"
}
}
archiveArtifacts artifacts: "${env.BUILD_AGENT}_${env.BUILD_TYPE}/Testing/**/*.xml, ${env.BUILD_AGENT}_${env.BUILD_TYPE}/gtest/**/*.xml", fingerprint: true
script {
if (isUnix()) {
sh "mv ${env.BUILD_AGENT}_${env.BUILD_TYPE} ${env.BUILD_TYPE}"
} else {
bat "rename ${env.BUILD_AGENT}_${env.BUILD_TYPE} ${env.BUILD_TYPE}"
}
}
xunit (
thresholds: [ skipped(failureThreshold: '0'), failed(failureThreshold: '0') ],
tools: [
CTest(pattern: "${env.BUILD_TYPE}/Testing/**/*.xml", deleteOutputFiles: true, failIfNotNew: false, skipNoTestFiles: true, stopProcessingIfError: true),
GoogleTest(pattern: "${env.BUILD_TYPE}/gtest/**/*.xml", deleteOutputFiles: true, failIfNotNew: false, skipNoTestFiles: true, stopProcessingIfError: true)
]
)
}
}
}
stage('Pack') {
agent {
node {
label env.BUILD_AGENT == 'Any' ? '' : env.BUILD_AGENT
customWorkspace "${env.JOB_NAME}/${env.BUILD_AGENT}/${env.BUILD_TYPE}"
}
}
steps {
unstash "build_${env.BUILD_AGENT}_${env.BUILD_TYPE}"
script {
if (isUnix()) {
sh 'make package'
} else {
withEnv(['PACK_FORMAT=ZIP']) {
bat 'make package'
}
}
}
}
post {
success {
script {
if (isUnix()) {
env.PACKAGE_FILE_NAME = sh(script: 'make --no-print-directory package_file_name', returnStdout: true).trim()
sh "mv ${env.BUILD_TYPE} ${env.BUILD_AGENT}_${env.BUILD_TYPE}"
} else {
env.PACKAGE_FILE_NAME = bat(script: '@make package_file_name', returnStdout: true).trim()
bat "rename ${env.BUILD_TYPE} ${env.BUILD_AGENT}_${env.BUILD_TYPE}"
}
}
archiveArtifacts artifacts: "${env.BUILD_AGENT}_${env.BUILD_TYPE}/${env.PACKAGE_FILE_NAME}*", fingerprint: true
script {
if (isUnix()) {
sh "mv ${env.BUILD_AGENT}_${env.BUILD_TYPE} ${env.BUILD_TYPE}"
} else {
bat "rename ${env.BUILD_AGENT}_${env.BUILD_TYPE} ${env.BUILD_TYPE}"
}
}
}
}
}
stage('Coverage') {
agent {
node {
label env.BUILD_AGENT == 'Any' ? '' : env.BUILD_AGENT
customWorkspace "${env.JOB_NAME}/${env.BUILD_AGENT}/${env.BUILD_TYPE}"
}
}
steps {
unstash "test_${env.BUILD_AGENT}_${env.BUILD_TYPE}"
script {
if (isUnix()) {
sh 'make coverage'
} else {
bat 'make coverage'
}
}
}
post {
success {
script {
if (isUnix()) {
env.PROJECT_NAME = sh(script: 'make --no-print-directory project_name', returnStdout: true).trim()
env.COVERAGE_REPORT_DIR = sh(script: "ls -td1 ${env.BUILD_TYPE}/${env.PROJECT_NAME}/coverage/CoverageReport-*/ | head -n1", returnStdout: true).trim()
env.COVERAGE_REPORT_FILE = 'CoverageReport.html'
sh "mv ${env.BUILD_TYPE} ${env.BUILD_AGENT}_${env.BUILD_TYPE}"
} else {
env.PROJECT_NAME = bat(script: '@make project_name', returnStdout: true).trim()
env.COVERAGE_REPORT_DIR = bat(script: "@dir /b /s /ad /o-n ${env.BUILD_TYPE}\\${env.PROJECT_NAME}\\coverage\\CoverageReport-*", returnStdout: true).split('\n')[0].trim()
env.COVERAGE_REPORT_FILE = 'index.html'
bat "rename ${env.BUILD_TYPE} ${env.BUILD_AGENT}_${env.BUILD_TYPE}"
}
}
archiveArtifacts artifacts: "${env.BUILD_AGENT}_${env.BUILD_TYPE}/**/coverage/", fingerprint: true
script {
if (isUnix()) {
sh "mv ${env.BUILD_AGENT}_${env.BUILD_TYPE} ${env.BUILD_TYPE}"
} else {
bat "rename ${env.BUILD_AGENT}_${env.BUILD_TYPE} ${env.BUILD_TYPE}"
}
}
publishHTML target: [
allowMissing: false,
alwaysLinkToLastBuild: false,
keepAll: true,
reportDir: env.COVERAGE_REPORT_DIR,
reportFiles: env.COVERAGE_REPORT_FILE,
reportName: "Coverage Report (${env.BUILD_AGENT} - ${env.BUILD_TYPE})"
]
}
}
}
stage('Doxygen') {
agent {
node {
label env.BUILD_AGENT == 'Any' ? '' : env.BUILD_AGENT
customWorkspace "${env.JOB_NAME}/${env.BUILD_AGENT}/${env.BUILD_TYPE}"
}
}
steps {
unstash "build_${env.BUILD_AGENT}_${env.BUILD_TYPE}"
script {
if (isUnix()) {
sh 'make --no-print-directory doxygen'
} else {
bat 'make doxygen'
}
}
}
post {
success {
script {
if (isUnix()) {
sh "mv doxygen ${env.BUILD_AGENT}_${env.BUILD_TYPE}_doxygen"
} else {
bat "rename doxygen ${env.BUILD_AGENT}_${env.BUILD_TYPE}_doxygen"
}
}
archiveArtifacts artifacts: "${env.BUILD_AGENT}_${env.BUILD_TYPE}_doxygen/", fingerprint: true
script {
if (isUnix()) {
sh "mv ${env.BUILD_AGENT}_${env.BUILD_TYPE}_doxygen doxygen"
} else {
bat "rename ${env.BUILD_AGENT}_${env.BUILD_TYPE}_doxygen doxygen"
}
}
publishHTML target: [
allowMissing: false,
alwaysLinkToLastBuild: false,
keepAll: true,
reportDir: 'doxygen/html/',
reportFiles: 'index.html',
reportName: "Doxygen (${env.BUILD_AGENT} - ${env.BUILD_TYPE})"
]
}
}
}
}
}
}
stage('Deploy') {
when { expression { params.ENABLE_DEPLOY_STAGE } }
steps {
input 'Deploy?'
}
}
}
}