forked from CentOS-PaaS-SIG/ci-pipeline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
JenkinsfileStageTrigger
336 lines (326 loc) · 17 KB
/
JenkinsfileStageTrigger
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
/**
* CI Stage Pipeline Trigger
*
* This is a declarative pipeline for the CI stage pipeline
* that includes the building of images based on PRs
*
*/
// Openshift project
openshiftProject = "continuous-infra"
DOCKER_REPO_URL = '172.30.254.79:5000'
// Defaults for SCM operations
env.ghprbGhRepository = env.ghprbGhRepository ?: 'CentOS-PaaS-SIG/ci-pipeline'
env.ghprbActualCommit = env.ghprbActualCommit ?: 'master'
// If this PR does not include an image change, then use this tag
STABLE_LABEL = "stable"
tagMap = [:]
// Initialize
tagMap['jenkins-continuous-infra-slave'] = STABLE_LABEL
tagMap['rpmbuild'] = STABLE_LABEL
tagMap['rsync'] = STABLE_LABEL
tagMap['ostree-compose'] = STABLE_LABEL
tagMap['ostree-image-compose'] = STABLE_LABEL
tagMap['singlehost-test'] = STABLE_LABEL
tagMap['ostree-boot-image'] = STABLE_LABEL
tagMap['linchpin-libvirt'] = STABLE_LABEL
// Fedora Fedmsg Message Provider for stage
MSG_PROVIDER = "fedora-fedmsg-stage"
// IRC properties
IRC_NICK = "contra-bot"
IRC_CHANNEL = "#contra-ci-cd"
// CI_MESSAGES known to build successfully
CANNED_CI_MESSAGES = [:]
CANNED_CI_MESSAGES['f26'] = '{"commit":{"username":"zdohnal","stats":{"files":{"README.patches":{"deletions":0,"additions":30,"lines":30},"sources":{"deletions":1,"additions":1,"lines":2},"vim.spec":{"deletions":7,"additions":19,"lines":26},".gitignore":{"deletions":0,"additions":1,"lines":1},"vim-8.0-rhbz1365258.patch":{"deletions":0,"additions":12,"lines":12}},"total":{"deletions":8,"files":5,"additions":63,"lines":71}},"name":"Zdenek Dohnal","rev":"3ff427e02625f810a2cedb754342be44d6161b39","namespace":"rpms","agent":"zdohnal","summary":"Merge branch f25 into f26","repo":"vim","branch":"f26","seen":false,"path":"/srv/git/repositories/rpms/vim.git","message":"Merge branch \'f25\' into f26\\n","email":"[email protected]"},"topic":"org.fedoraproject.prod.git.receive"}'
CANNED_CI_MESSAGES['f27'] = '{"commit":{"username":"adrian","stats":{"files":{"criu.spec":{"deletions":0,"additions":5,"lines":5}},"total":{"deletions":0,"files":1,"additions":5,"lines":5}},"name":"Adrian Reber","rev":"386bedee49cb887626140f2c60522751ec620f1d","namespace":"rpms","agent":"adrian","summary":"Adapt ExcludeArch depending on Fedora release","repo":"criu","branch":"f27","seen":false,"path":"/srv/git/repositories/rpms/criu.git","message":"Adapt ExcludeArch depending on Fedora release\\n","email":"[email protected]"},"topic":"org.fedoraproject.prod.git.receive"}'
// Specific canned messages
CANNED_CI_MESSAGES['f26-singlehost-test'] = '{"commit":{"username":"kdudka","stats":{"files":{"curl.spec":{"deletions":1,"additions":8,"lines":9},"0005-curl-7.53.1-CVE-2017-1000254.patch":{"deletions":0,"additions":136,"lines":136}},"total":{"deletions":1,"files":2,"additions":144,"lines":145}},"name":"Kamil Dudka","rev":"d1d232206aed8ef12596ec3939b72a6476845149","namespace":"rpms","agent":"kdudka","summary":"Resolves: CVE-2017-1000254 - fix out of bounds read in FTP PWD response parser","repo":"curl","branch":"f26","seen":false,"path":"/srv/git/repositories/rpms/curl.git","message":"Resolves: CVE-2017-1000254 - fix out of bounds read in FTP PWD response parser\\n","email":"[email protected]"},"topic":"org.fedoraproject.prod.git.receive"}'
CANNED_CI_MESSAGES['f27-singlehost-test'] = '{"commit":{"username":"kdudka","stats":{"files":{"curl.spec":{"deletions":4,"additions":11,"lines":15},"0005-curl-7.55.1-CVE-2017-1000254.patch":{"deletions":0,"additions":136,"lines":136}},"total":{"deletions":4,"files":2,"additions":147,"lines":151}},"name":"Kamil Dudka","rev":"9765ef0484ffde44a0104d919799f461b3cb802d","namespace":"rpms","agent":"kdudka","summary":"Resolves: CVE-2017-1000254 - fix out of bounds read in FTP PWD response parser","repo":"curl","branch":"f27","seen":false,"path":"/srv/git/repositories/rpms/curl.git","message":"Resolves: CVE-2017-1000254 - fix out of bounds read in FTP PWD response parser\\n","email":"[email protected]"},"topic":"org.fedoraproject.prod.git.receive"}'
library identifier: "ci-pipeline@${env.ghprbActualCommit}",
retriever: modernSCM([$class: 'GitSCMSource',
remote: "https://github.com/${env.ghprbGhRepository}",
traits: [[$class: 'jenkins.plugins.git.traits.BranchDiscoveryTrait'],
[$class: 'RefSpecsSCMSourceTrait',
templates: [[value: '+refs/heads/*:refs/remotes/@{remote}/*'],
[value: '+refs/pull/*:refs/remotes/origin/pr/*']]]]])
properties([
buildDiscarder(logRotator(artifactNumToKeepStr: '20', numToKeepStr: '20')),
[$class: 'GithubProjectProperty', displayName: '', projectUrlStr: 'https://github.com/CentOS-PaaS-SIG/ci-pipeline/'],
[$class: 'org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty', triggers:[
[
$class: 'org.jenkinsci.plugins.ghprb.GhprbTrigger',
orgslist: 'CentOS-PaaS-SIG',
cron: 'H/5 * * * *',
triggerPhrase: '.*\\[test\\].*',
onlyTriggerPhrase: false,
useGitHubHooks: true,
permitAll: true,
autoCloseFailedPullRequests: false,
displayBuildErrorsOnDownstreamBuilds: true,
extensions: [
[
$class: 'org.jenkinsci.plugins.ghprb.extensions.status.GhprbSimpleStatus',
commitStatusContext: 'Atomic Stage Job',
showMatrixStatus: false,
triggeredStatus: 'Starting job...',
startedStatus: 'Building...',
]
]
]
]]
])
pipeline {
agent {
kubernetes {
cloud 'openshift'
label 'stage-trigger-' + env.ghprbActualCommit
containerTemplate {
name 'jnlp'
args '${computer.jnlpmac} ${computer.name}'
image DOCKER_REPO_URL + '/' + openshiftProject + '/jenkins-continuous-infra-slave:' + STABLE_LABEL
ttyEnabled false
command ''
}
}
}
stages {
stage("Get Changelog") {
steps {
node('master') {
script {
echo "PR number is: ${env.ghprbPullId}"
env.changeLogStr = pipelineUtils.getChangeLogFromCurrentBuild()
echo env.changeLogStr
}
writeFile file: 'changelog.txt', text: env.changeLogStr
archiveArtifacts allowEmptyArchive: true, artifacts: 'changelog.txt'
}
}
}
stage("Setup Container Templates") {
steps {
script {
pipelineUtils.setupContainerTemplates(openshiftProject)
}
}
}
stage("jenkins-continuous-infra-slave image build") {
when {
// Only build if we have related files in changeset
changeset "config/s2i/jenkins/slave/**"
}
steps {
script {
tagMap['jenkins-continuous-infra-slave'] = pipelineUtils.buildImage(openshiftProject, "jenkins-continuous-infra-slave")
}
}
}
stage("rpmbuild image build") {
when {
// Only build if we have related files in changeset
changeset "config/Dockerfiles/rpmbuild/**"
}
steps {
script {
tagMap['rpmbuild'] = pipelineUtils.buildImage(openshiftProject, "rpmbuild")
}
}
}
stage("rsync image build") {
when {
// Only build if we have related files in changeset
changeset "config/Dockerfiles/rsync/**"
}
steps {
script {
tagMap['rsync'] = pipelineUtils.buildImage(openshiftProject, "rsync")
}
}
}
stage("ostree-compose image build") {
when {
// Only build if we have related files in changeset
changeset "config/Dockerfiles/ostree_compose/**"
}
steps {
script {
tagMap['ostree-compose'] = pipelineUtils.buildImage(openshiftProject, "ostree-compose")
}
}
}
stage("ostree-image-compose image build") {
when {
// Only build if we have related files in changeset
changeset "config/Dockerfiles/ostree-image-compose/**"
}
steps {
script {
tagMap['ostree-image-compose'] = pipelineUtils.buildImage(openshiftProject, "ostree-image-compose")
}
}
}
stage("singlehost-test image build") {
when {
// Only build if we have related files in changeset
changeset "config/Dockerfiles/singlehost-test/**"
}
steps {
script {
tagMap['singlehost-test'] = pipelineUtils.buildImage(openshiftProject, "singlehost-test")
// Map canned message to proper one for testing
CANNED_CI_MESSAGES['f26'] = CANNED_CI_MESSAGES['f26-singlehost-test']
CANNED_CI_MESSAGES['f27'] = CANNED_CI_MESSAGES['f27-singlehost-test']
}
}
}
stage("ostree-boot-image image build") {
when {
// Only build if we have related files in changeset
changeset "config/Dockerfiles/ostree-boot-image/**"
}
steps {
script {
tagMap['ostree-boot-image'] = pipelineUtils.buildImage(openshiftProject, "ostree-boot-image")
}
}
}
stage("linchpin-libvirt image build") {
when {
// Only build if we have related files in changeset
changeset "config/Dockerfiles/linchpin-libvirt/**"
}
steps {
script {
tagMap['linchpin-libvirt'] = pipelineUtils.buildImage(openshiftProject, "linchpin-libvirt")
}
}
}
stage("Image Tag Report") {
steps {
script {
// Use tags derived from above image builds
//
pipelineUtils.printLabelMap(tagMap)
}
}
}
stage("Run Stage Jobs") {
failFast true
parallel {
//stage("f26 message watcher") {
//steps {
//script {
//pipelineUtils.watchForMessages(MSG_PROVIDER, CANNED_CI_MESSAGES['f26'])
//}
//}
//}
stage("f27 message watcher") {
steps {
script {
pipelineUtils.watchForMessages(MSG_PROVIDER, CANNED_CI_MESSAGES['f27'])
}
}
}
//stage("f26 stage job") {
//steps {
//sleep 30
//build job: 'ci-stage-pipeline-f26',
//parameters: [
//string(name: 'CI_MESSAGE',
// value: CANNED_CI_MESSAGES['f26']),
//string(name: 'ghprbActualCommit',
// value: "${env.ghprbActualCommit}"),
//string(name: 'ghprbGhRepository',
// value: "${env.ghprbGhRepository}"),
//string(name: 'ghprbPullAuthorLogin',
// value: "${env.ghprbPullAuthorLogin}"),
//string(name: 'TARGET_BRANCH',
// value: "f26"),
//string(name: 'sha1',
// value: "${env.sha1}"),
//string(name: 'ghprbPullId',
// value: "${env.ghprbPullId}"),
//string(name: 'GENERATE_IMAGE',
// value: "true"),
//string(name: 'SLAVE_TAG',
// value: tagMap['jenkins-continuous-infra-slave']),
//string(name: 'RPMBUILD_TAG',
// value: tagMap['rpmbuild']),
//string(name: 'RSYNC_TAG',
// value: tagMap['rsync']),
//string(name: 'OSTREE_COMPOSE_TAG',
// value: tagMap['ostree-compose']),
//string(name: 'OSTREE_IMAGE_COMPOSE_TAG',
// value: tagMap['ostree-image-compose']),
//string(name: 'SINGLEHOST_TEST_TAG',
// value: tagMap['singlehost-test']),
//string(name: 'OSTREE_BOOT_IMAGE_TAG',
// value: tagMap['ostree-boot-image']),
//string(name: 'LINCHPIN_LIBVIRT_TAG',
// value: tagMap['linchpin-libvirt'])
//],
//wait: true
//}
//}
stage("f27 stage job") {
steps {
sleep 30
build job: 'ci-stage-pipeline-f27',
parameters: [
string(name: 'CI_MESSAGE',
value: CANNED_CI_MESSAGES['f27']),
string(name: 'ghprbActualCommit',
value: "${env.ghprbActualCommit}"),
string(name: 'ghprbGhRepository',
value: "${env.ghprbGhRepository}"),
string(name: 'ghprbPullAuthorLogin',
value: "${env.ghprbPullAuthorLogin}"),
string(name: 'TARGET_BRANCH',
value: "f27"),
string(name: 'sha1',
value: "${env.sha1}"),
string(name: 'ghprbPullId',
value: "${env.ghprbPullId}"),
string(name: 'GENERATE_IMAGE',
value: "true"),
string(name: 'SLAVE_TAG',
value: tagMap['jenkins-continuous-infra-slave']),
string(name: 'RPMBUILD_TAG',
value: tagMap['rpmbuild']),
string(name: 'RSYNC_TAG',
value: tagMap['rsync']),
string(name: 'OSTREE_COMPOSE_TAG',
value: tagMap['ostree-compose']),
string(name: 'OSTREE_IMAGE_COMPOSE_TAG',
value: tagMap['ostree-image-compose']),
string(name: 'SINGLEHOST_TEST_TAG',
value: tagMap['singlehost-test']),
string(name: 'OSTREE_BOOT_IMAGE_TAG',
value: tagMap['ostree-boot-image']),
string(name: 'LINCHPIN_LIBVIRT_TAG',
value: tagMap['linchpin-libvirt'])
],
wait: true
}
}
}
}
}
post {
always {
script {
String prMsg = ""
if (env.ghprbActualCommit != null && env.ghprbActualCommit != "master") {
prMsg = "(PR #${env.ghprbPullId} ${env.ghprbPullAuthorLogin})"
}
def message = "${JOB_NAME} ${prMsg} build #${BUILD_NUMBER}: ${currentBuild.currentResult}: ${BUILD_URL}"
pipelineUtils.sendIRCNotification("${IRC_NICK}-${UUID.randomUUID()}", IRC_CHANNEL, message)
}
}
success {
echo "yay!"
}
failure {
error "build failed!"
}
}
}