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
/
JenkinsfilePRCommentTrigger
132 lines (109 loc) · 6.88 KB
/
JenkinsfilePRCommentTrigger
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
#!groovy
timestamps {
// canned CI_MESSAGE
// Might just keep this for legacy reasons for now
def CANNED_CI_MESSAGE = '{"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"}'
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]])
}
//noinspection GroovyAssignabilityCheck
properties(
[
buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '100', daysToKeepStr: '', numToKeepStr: '100')),
pipelineTriggers(
[[$class: 'CIBuildTrigger',
noSquash: true,
providerData: [
$class: 'RabbitMQSubscriberProviderData',
name: 'FedoraMessaging',
overrides: [
topic: 'org.fedoraproject.prod.pagure.pull-request.comment.added',
queue: 'osci-pipelines-queue-9'
],
checks: [
[field: '$.pullrequest.project.namespace', expectedValue: 'rpms|tests'],
[field: '$.pullrequest.status', expectedValue: 'Open']
]
]
]]
),
parameters(
[
string(defaultValue: CANNED_CI_MESSAGE, description: 'CI_MESSAGE', name: 'CI_MESSAGE')
]
)
]
)
def TRIGGER_RETRY_COUNT = 3
def validMessage = true
def testsExist = false
def stepName = null
node('master') {
// pull in ciMetrics from ci-pipeline
// ciMetrics.prefix = packagepipelineUtils.influxDBPrefix()
// packagepipelineUtils.cimetrics = ciMetrics
// def jobMeasurement = packagepipelineUtils.timedMeasurement()
timeout(time: 30, unit: 'MINUTES') {
packagepipelineUtils.ciPipeline {
try {
stepName = 'fedora-pr-pipeline-trigger'
stage(stepName) {
packagepipelineUtils.handlePipelineStep(stepName: stepName, debug: true) {
print "CI_MESSAGE"
print CI_MESSAGE
packagepipelineUtils.setDefaultEnvVars()
parsedMsg = kojiMessage(message: env.CI_MESSAGE, ignoreErrors: true)
currentBuild.displayName = "BUILD#: ${env.BUILD_NUMBER} - Branch: ${parsedMsg['pullrequest']['branch']} - Package: ${parsedMsg['pullrequest']['project']['name']}"
validMessage = packagepipelineUtils.checkBranch(parsedMsg['pullrequest']['branch'])
// Function only returns false if comments exist,
// but the latest was uninteresting
commentTrigger = contraUtils.checkUpdatedPR(env.CI_MESSAGE, '[citest]')
if (validMessage && commentTrigger) {
testsExist = contraUtils.checkTests(parsedMsg['pullrequest']['project']['name'], parsedMsg['pullrequest']['branch'], 'classic', parsedMsg['pullrequest']['id'].toString(), parsedMsg['pullrequest']['project']['namespace'])
}
}
}
if (validMessage && testsExist && commentTrigger) {
// Send message org.centos.prod.ci.dist-git-pr.test.queued on fedmsg
messageFields = packagepipelineUtils.setMessageFields("queued", "dist-git-pr", parsedMsg)
contraUtils.sendMessage(messageFields['topic'], messageFields['properties'], messageFields['content'])
stepName = 'schedule build'
stage(stepName) {
try {
retry(TRIGGER_RETRY_COUNT) {
packagepipelineUtils.handlePipelineStep(stepName: stepName, debug: true) {
branch = (parsedMsg['pullrequest']['branch'] == 'master') ? 'rawhide' : parsedMsg['pullrequest']['branch']
build job: "fedora-${branch}-pr-pipeline",
parameters: [string(name: 'CI_MESSAGE', value: env.CI_MESSAGE),
string(name: 'pipelineId', value: UUID.randomUUID().toString())],
wait: false
}
}
} catch (Throwable err) {
currentBuild.description = "*TRIGGER FAILURE*"
error "Error: Build could not be added to queue after " + TRIGGER_RETRY_COUNT + " tries"
throw err
}
}
} else {
echo "CI_MESSAGE was invalid. Skipping..."
currentBuild.description = "*Build Skipped*"
}
currentBuild.result = 'SUCCESS'
} catch (Throwable err) {
currentBuild.result = 'FAILURE'
throw err
} // 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())
// }
}
}
}
}