forked from CentOS-PaaS-SIG/upstream-fedora-pipeline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
JenkinsfileStageBuildTrigger
177 lines (157 loc) · 9.42 KB
/
JenkinsfileStageBuildTrigger
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
#!groovy
def parseText(message) {
if (!message) {
return null
}
def parsed = readJSON text: message.replace("\n", "\\n")
return parsed
}
timestamps {
def libraries = ['upstream-fedora-pipeline': ['master', 'https://github.com/CentOS-PaaS-SIG/upstream-fedora-pipeline.git'],
'contra-lib' : ['master', 'https://github.com/openshift/contra-lib.git']]
libraries.each { name, repo ->
library identifier: "${name}@${repo[0]}",
retriever: modernSCM([$class: 'GitSCMSource',
remote: repo[1]])
}
env.ghprbActualCommit = env.ghprbActualCommit ?: 'master'
properties(
[
buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '500', daysToKeepStr: '', numToKeepStr: '500')),
parameters(
[
string(description: 'CI message', defaultValue: '{}', name: 'CI_MESSAGE'),
string(name: 'MSG_PROVIDER',
defaultValue: 'FedoraMessagingStage',
description: 'Main provider to send messages on'),
string(name: 'KOJI_URL',
defaultValue: 'https://koji.stg.fedoraproject.org',
description: 'URL of koji instance'),
string(name: 'KOJI_PARAMS',
defaultValue: '--server https://koji.stg.fedoraproject.org/kojihub --topurl https://kojipkgs.stg.fedoraproject.org',
description: 'Parameters to pass to koji tool'),
string(name: 'ghprbActualCommit',
defaultValue: 'master',
description: 'The GitHub pull request commit'),
string(name: 'ghprbGhRepository',
defaultValue: '',
description: 'The repo the PR is against'),
string(name: 'sha1',
defaultValue: '',
description: ''),
string(name: 'ghprbPullId',
defaultValue: '',
description: 'Pull Request Number'),
string(name: 'ghprbPullAuthorLogin',
defaultValue: '',
description: 'Pull Request Author username'),
string(name: 'SLAVE_TAG',
defaultValue: 'stable',
description: 'Tag for slave image'),
string(name: 'FEDORACI_RUNNER_TAG',
defaultValue: 'stable',
description: 'Tag for fedoraci-runner image'),
]
),
pipelineTriggers(
[[$class: 'CIBuildTrigger',
noSquash: true,
providerData: [
$class: 'RabbitMQSubscriberProviderData',
name: 'FedoraMessagingStage',
overrides: [
topic: 'org.fedoraproject.stg.bodhi.update.status.testing.koji-build-group.build.complete',
queue: 'osci-pipelines-queue-6'
]
]
]]
)
]
)
def TRIGGER_RETRY_COUNT = 3
def stepName = null
node('master') {
packagepipelineUtils.ciPipeline {
try {
stepName = 'upstream-fedora-pipeline-build-trigger'
stage(stepName) {
packagepipelineUtils.handlePipelineStep(stepName: stepName, debug: true) {
print "CI_MESSAGE"
print CI_MESSAGE
parsedMsg = parseText(env.CI_MESSAGE)
packagepipelineUtils.setDefaultEnvVars()
targetBranch = false
env.fed_branch = parsedMsg['artifact']['release']
env.branch = parsedMsg['artifact']['release']
env.isScratch = false
def rawhide_release = packagepipelineUtils.getRawhideRelease()
if (env.fed_branch == "f${rawhide_release}") {
env.fed_branch = 'master'
env.branch = 'rawhide'
}
if (env.branch != 'rawhide') {
error("FAIL: unsupported release ${env.branch}")
}
}
}
stepName = 'schedule build'
stage(stepName) {
packagepipelineUtils.handlePipelineStep(stepName: stepName, debug: true) {
env.currentStage = stepName
def builds = parsedMsg['artifact']['builds']
for (newbuild in builds) {
env.fed_repo = newbuild['component']
env.nvr = newbuild['nvr']
env.build_id = newbuild['id']
env.issuer = newbuild['issuer']
env.task_id = newbuild['task_id']
env.ADDITIONAL_TASK_IDS = ''
for (tmpbuild in builds) {
if (tmpbuild['task_id'] != newbuild['task_id']) {
env.ADDITIONAL_TASK_IDS += "${tmpbuild['task_id']} "
}
}
testsExist = contraUtils.checkTests(env.fed_repo, env.fed_branch, 'classic')
if (testsExist && env.branch == 'rawhide') {
currentBuild.displayName = "BUILD#: ${env.BUILD_NUMBER} - Release: ${env.branch} - Package: ${env.fed_repo}"
// Send message org.centos.prod.ci.koji-build.test.queued on fedmsg
messageFields = packagepipelineUtils.setMessageFields("queued", "koji-build", parsedMsg)
contraUtils.sendMessage(messageFields['topic'], messageFields['properties'], messageFields['content'])
retry(TRIGGER_RETRY_COUNT) {
build job: "fedora-rawhide-stage-build-pipeline",
parameters: [string(name: 'PROVIDED_KOJI_TASKID', value: env.task_id),
string(name: 'ADDITIONAL_TASK_IDS', value: env.ADDITIONAL_TASK_IDS),
string(name: 'MSG_PROVIDER', value: env.MSG_PROVIDER),
string(name: 'KOJI_URL', value: env.KOJI_URL),
string(name: 'KOJI_PARAMS', value: env.KOJI_PARAMS),
string(name: 'ghprbActualCommit',
value: "${env.ghprbActualCommit}"),
string(name: 'ghprbGhRepository',
value: "${env.ghprbGhRepository}"),
string(name: 'ghprbPullAuthorLogin',
value: "${env.ghprbPullAuthorLogin}"),
string(name: 'sha1',
value: "${env.sha1}"),
string(name: 'ghprbPullId',
value: "${env.ghprbPullId}"),
string(name: 'SLAVE_TAG',
value: env.SLAVE_TAG),
string(name: 'FEDORACI_RUNNER_TAG',
value: env.FEDORACI_RUNNER_TAG),
string(name: 'CI_MESSAGE', value: env.CI_MESSAGE)],
wait: false
}
} else {
currentBuild.displayName = "Build#: ${env.BUILD_NUMBER} - Release: ${env.branch} - Package: ${env.fed_repo} - Skipped"
}
}
}
}
currentBuild.result = 'SUCCESS'
} catch (e) {
currentBuild.result = 'FAILURE'
throw e
}
}
}
}