This repository has been archived by the owner on Jun 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 41
/
Jenkinsfile
344 lines (336 loc) · 11 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
338
339
340
341
342
343
344
#!/usr/bin/env groovy
// vim: set et sw=4 ts=4 :
String distSubDir() {
try {
"${CHANGE_ID}"
return 'prs/'
} catch (Exception ex) {
switch (env.BRANCH_NAME) {
case 'develop':
return 'develop/'
case 'master':
return 'master/'
default:
return 'branches/'
}
}
}
String distPrefix() {
try {
return "PR-${CHANGE_ID}-"
} catch (Exception ex) {
if (env.BRANCH_NAME == 'develop' || env.BRANCH_NAME == 'master') {
return ''
}
return java.net.URLEncoder.encode("${BRANCH_NAME}-", "UTF-8")
}
}
pipeline {
agent any
options {
ansiColor('xterm')
disableConcurrentBuilds() // Otherwise clean would delete the images
skipDefaultCheckout() // We do our own checkout so it can be disabled
timestamps()
timeout(time: 10, unit: 'HOURS')
ws('scf')
}
parameters {
booleanParam(
name: 'SKIP_CHECKOUT',
defaultValue: false,
description: 'Skip the checkout step for faster iteration',
)
booleanParam(
name: 'WIPE',
defaultValue: false,
description: 'Remove all existing sources and start from scratch',
)
booleanParam(
name: 'CLEAN',
defaultValue: true,
description: 'Remove build artifacts that should normally not be reused',
)
booleanParam(
name: 'PUBLISH_DOCKER',
defaultValue: true,
description: 'Enable publishing to docker',
)
booleanParam(
name: 'PUBLISH_S3',
defaultValue: true,
description: 'Enable publishing to amazon s3',
)
booleanParam(
name: 'TEST',
defaultValue: true,
description: 'Trigger tests after publishing',
)
booleanParam(
name: 'TEST_CATS',
defaultValue: false,
description: 'Trigger CATS in the test run',
)
booleanParam(
name: 'TAR_SOURCES',
defaultValue: false,
description: 'Tar sources',
)
booleanParam(
name: 'COMMIT_SOURCES',
defaultValue: false,
description: 'Push sources to obs',
)
credentials(
name: 'OBS_CREDENTIALS',
description: 'Password for build.opensuse.org',
defaultValue: 'osc-alfred-jenkins',
)
credentials(
name: 'S3_CREDENTIALS',
description: 'AWS access key / secret key used for publishing',
defaultValue: 'cred-s3-scf',
)
string(
name: 'S3_REGION',
description: 'AWS S3 region the target bucket is in',
defaultValue: 'us-east-1',
)
string(
name: 'S3_BUCKET',
description: 'AWS S3 bucket to publish to',
defaultValue: 'cf-opensusefs2',
)
string(
name: 'S3_PREFIX',
description: 'AWS S3 prefix to publish to',
defaultValue: 'scf/config/',
)
credentials(
name: 'DOCKER_CREDENTIALS',
description: 'Docker credentials used for publishing',
defaultValue: 'cred-docker-scf',
)
string(
name: 'FISSILE_DOCKER_REGISTRY',
defaultValue: '',
description: 'Docker registry to publish to',
)
string(
name: 'FISSILE_DOCKER_ORGANIZATION',
defaultValue: 'splatform',
description: 'Docker organization to publish to',
)
string(
name: 'FISSILE_STEMCELL',
defaultValue: '',
description: 'Override the .envrc configured stemcell. .envrc is used if left blank.',
)
string(
name: 'FISSILE_STEMCELL_VERSION',
defaultValue: '',
description: 'Override the .envrc configured stemcell version. .envrc is used if left blank.',
)
booleanParam(
name: 'TRIGGER_SLES_BUILD',
defaultValue: true,
description: 'Trigger a SLES version of this job',
)
}
environment {
FISSILE_DOCKER_REGISTRY = "${params.FISSILE_DOCKER_REGISTRY}"
FISSILE_DOCKER_ORGANIZATION = "${params.FISSILE_DOCKER_ORGANIZATION}"
FISSILE_STEMCELL = "${params.FISSILE_STEMCELL}"
FISSILE_STEMCELL_VERSION = "${params.FISSILE_STEMCELL_VERSION}"
}
stages {
stage('trigger_sles_build') {
when {
expression { return params.TRIGGER_SLES_BUILD }
}
steps {
build job: 'scf-sles-trigger', wait: false, parameters: [string(name: 'JOB_NAME', value: env.JOB_NAME)]
}
}
stage('wipe') {
when {
expression { return params.WIPE }
}
steps {
deleteDir()
}
}
stage('clean') {
when {
expression { return params.CLEAN }
}
steps {
sh '''
docker images --format="{{.Repository}}:{{.Tag}}" | \
grep -E '/scf-|/uaa-|^uaa-role-packages:|^scf-role-packages:' | \
xargs --no-run-if-empty docker rmi
'''
}
}
stage('checkout') {
when {
expression { return (!params.SKIP_CHECKOUT) || params.WIPE }
}
steps {
sh '''
git config --global --replace-all submodule.fetchJobs 0
'''
checkout scm
}
}
stage('tools') {
steps {
sh '''
set -e +x
source ${PWD}/.envrc
set -x
unset HCF_PACKAGE_COMPILATION_CACHE
make ${FISSILE_BINARY}
'''
}
}
stage('build') {
steps {
withCredentials([usernamePassword(
credentialsId: params.DOCKER_CREDENTIALS,
usernameVariable: 'DOCKER_HUB_USERNAME',
passwordVariable: 'DOCKER_HUB_PASSWORD',
)]) {
sh '''
if [ -n "${FISSILE_DOCKER_REGISTRY}" ]; then
docker login -u "${DOCKER_HUB_USERNAME}" -p "${DOCKER_HUB_PASSWORD}" "${FISSILE_DOCKER_REGISTRY}"
fi
'''
}
sh '''
set -e +x
source ${PWD}/.envrc
set -x
unset HCF_PACKAGE_COMPILATION_CACHE
make vagrant-prep validate
'''
}
}
stage('tar_sources') {
when {
expression { return params.TAR_SOURCES }
}
steps {
sh '''
set -e +x
source ${PWD}/.envrc
make compile-clean
'''
}
}
stage('commit_sources') {
when {
expression { return params.COMMIT_SOURCES }
}
steps {
withCredentials([usernamePassword(
credentialsId: params.OBS_CREDENTIALS,
usernameVariable: 'OBS_CREDENTIALS_USERNAME',
passwordVariable: 'OBS_CREDENTIALS_PASSWORD',
)]) {
sh '''
set -e +x
source ${PWD}/.envrc
echo -e "[general]
apiurl = https://api.opensuse.org
[https://api.opensuse.org]
user = ${OBS_CREDENTIALS_USERNAME}
pass = ${OBS_CREDENTIALS_PASSWORD}
" > ~/.oscrc
make osc-commit-sources
rm ~/.oscrc
'''
}
}
}
stage('dist') {
steps {
sh '''
set -e +x
source ${PWD}/.envrc
set -x
unset HCF_PACKAGE_COMPILATION_CACHE
rm -f scf-*amd64*.zip
make helm bundle-dist
'''
}
}
stage('publish_docker') {
when {
expression { return params.PUBLISH_DOCKER }
}
steps {
withCredentials([usernamePassword(
credentialsId: params.DOCKER_CREDENTIALS,
usernameVariable: 'DOCKER_HUB_USERNAME',
passwordVariable: 'DOCKER_HUB_PASSWORD',
)]) {
sh 'docker login -u "${DOCKER_HUB_USERNAME}" -p "${DOCKER_HUB_PASSWORD}" '
}
sh '''
set -e +x
source ${PWD}/.envrc
set -x
unset HCF_PACKAGE_COMPILATION_CACHE
make publish
'''
}
}
stage('publish_s3') {
when {
expression { return params.PUBLISH_S3 }
}
steps {
withAWS(region: params.S3_REGION) {
withCredentials([usernamePassword(
credentialsId: params.S3_CREDENTIALS,
usernameVariable: 'AWS_ACCESS_KEY_ID',
passwordVariable: 'AWS_SECRET_ACCESS_KEY',
)]) {
script {
def files = findFiles(glob: 'scf-*amd64*.zip')
def subdir = "${params.S3_PREFIX}${distSubDir()}"
def prefix = distPrefix()
for ( int i = 0 ; i < files.size() ; i ++ ) {
s3Upload(
file: files[i].path,
bucket: "${params.S3_BUCKET}",
path: "${subdir}${prefix}${files[i].name}",
)
}
}
}
}
}
}
stage('test') {
when {
expression { return params.PUBLISH && params.TEST }
}
steps {
script {
def files = findFiles(glob: 'scf-*.linux-amd64*.zip')
build(
job: 'scf-test',
parameters: [
string(name: 'CONFIG_NAME', value: distPrefix() + files[0].path),
string(name: 'CONFIG_PATH', value: 'https://s3.amazonaws.com/cf-opensusefs2/scf/config/' + distSubDir()),
booleanParam(name: 'RUN_CATS', value: params.TEST_CATS),
],
wait: false,
)
}
}
}
}
}