This repository has been archived by the owner on Sep 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
JenkinsfileTaskTrigger
136 lines (115 loc) · 6.3 KB
/
JenkinsfileTaskTrigger
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
#!groovy
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]])
}
// Audit file for all messages sent.
msgAuditFile = "messages/message-audit.json"
// Number of times to keep retrying to make sure message is ingested
// by datagrepper
fedmsgRetryCount = 120
properties(
[
buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '500', daysToKeepStr: '', numToKeepStr: '500')),
parameters(
[
string(description: 'CI message', defaultValue: '{}', name: 'CI_MESSAGE')
]
),
pipelineTriggers(
[[$class: 'CIBuildTrigger',
noSquash: true,
providerData: [
$class: 'RabbitMQSubscriberProviderData',
name: 'FedoraMessaging',
overrides: [
topic: 'org.fedoraproject.prod.buildsys.task.state.change',
queue: 'osci-pipelines-queue-3'
],
checks: [
[field: 'new', expectedValue: '1|CLOSED'],
[field: 'owner', expectedValue: '^(?!koschei).*']
]
]
]]
)
]
)
def TRIGGER_RETRY_COUNT = 3
def stepName = null
node('master') {
// pull in ciMetrics from ci-pipeline
// ciMetrics.prefix = packagepipelineUtils.influxDBPrefix()
// packagepipelineUtils.cimetrics = ciMetrics
// def jobMeasurement = packagepipelineUtils.timedMeasurement()
packagepipelineUtils.ciPipeline {
try {
stepName = 'upstream-fedora-pipeline-build-trigger'
stage(stepName) {
packagepipelineUtils.handlePipelineStep(stepName: stepName, debug: true) {
print "CI_MESSAGE"
print CI_MESSAGE
parsedMsg = kojiMessage(message: env.CI_MESSAGE, ignoreErrors: true)
packagepipelineUtils.setScratchVars(parsedMsg)
packagepipelineUtils.setDefaultEnvVars()
env.fed_repo = contraUtils.repoFromRequest(env.request_0)
targetBranch = false
if (env.isScratch.toBoolean()) {
env.task_id = parsedMsg['info']['id']
branches = contraUtils.setBuildBranch(env.request_1)
env.branch = branches[0]
env.fed_branch = branches[1]
targetBranch = packagepipelineUtils.checkBranch(env.fed_branch)
}
// If the PR pipeline submit the build, let's just set targetBranch to false so we don't run
if (parsedMsg['owner'] == "bpeck/jenkins-continuous-infra.apps.ci.centos.org" || parsedMsg['owner'] == "koschei") {
print("This build is for a scratch build from the PR pipeline. Not triggering.")
targetBranch = false
}
if (targetBranch) {
testsExist = contraUtils.checkTests(env.fed_repo, env.fed_branch, 'classic')
// Ensure message is from primary koji instance
primaryKoji = parsedMsg['instance'] == "primary"
currentBuild.displayName = "BUILD#: ${env.BUILD_NUMBER} - Branch: ${env.fed_branch} - Package: ${env.fed_repo}"
} else {
currentBuild.displayName = "Build#: ${env.BUILD_NUMBER} - Branch: ${env.fed_branch} - Skipped"
}
}
}
if (targetBranch && testsExist && primaryKoji) {
// 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'])
stepName = 'schedule build'
stage(stepName) {
retry(TRIGGER_RETRY_COUNT) {
packagepipelineUtils.handlePipelineStep(stepName: stepName, debug: true) {
build job: "fedora-${env.branch}-build-pipeline",
// Scratch messages from task.state.changed call it id, not task_id
parameters: [string(name: 'PROVIDED_KOJI_TASKID', value: env.task_id),
string(name: 'CI_MESSAGE', value: env.CI_MESSAGE)],
wait: false
}
}
}
} else {
echo "CI_MESSAGE was invalid. Skipping..."
currentBuild.description = "*Build Skipped*"
}
currentBuild.result = 'SUCCESS'
} catch (e) {
currentBuild.result = 'FAILURE'
throw e
} // finally {
// set the metrics we want
// ciMetrics.setMetricTag(jobMeasurement, 'package_name', env.fed_repo)
// ciMetrics.setMetricTag(jobMeasurement, 'build_result', currentBuild.result)
// ciMetrics.setMetricField(jobMeasurement, 'build_time', currentBuild.getDuration())
// }
}
}
}