This repository has been archived by the owner on Feb 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
/
submitToTreeherder.groovy
110 lines (101 loc) · 3.23 KB
/
submitToTreeherder.groovy
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
import groovy.json.JsonOutput
import java.text.SimpleDateFormat
/** Submit build results to Treeherder
*
* @param project project to submit results for
* @param jobSymbol symbol for the job
* @param jobName name for the job
* @param artifactPath path for artifact(s) to publish
* @param logPath path for log(s) to publish
* @param groupSymbol symbol for the job group
* @param groupName name for the job group
*/
def call(String project,
String jobSymbol,
String jobName,
String artifactPath = null,
String logPath = null,
String groupSymbol = '?',
String groupName = null) {
machine = getMachine()
payload = [
taskId: UUID.randomUUID().toString(),
buildSystem: machine['name'],
origin: [kind: 'github.com', project: project, revision: getRevision()],
display: [
jobSymbol: jobSymbol,
jobName: jobName,
groupSymbol: groupSymbol],
state: 'completed',
result: getResult(),
jobKind: 'test',
timeScheduled: getDateTime(currentBuild.timeInMillis),
timeStarted: getDateTime(currentBuild.startTimeInMillis),
timeCompleted: getDateTime(currentBuild.startTimeInMillis + currentBuild.duration),
reason: 'scheduled', // TODO build cause: currentBuild.rawBuild.getCause().getShortDescription()
productName: project,
buildMachine: machine,
runMachine: machine,
jobInfo: [links: getJobLinks(artifactPath)],
logs: getLogs(logPath),
version: 1
]
if ( groupName != null) {
payload.display.groupName = groupName
}
// TODO include ec2-metadata output in payload
exchange = "exchange/${PULSE_USR}/jobs"
routingKey = "${PULSE_USR}.${payload.productName}"
schema = libraryResource 'org/mozilla/fxtest/pulse/schemas/treeherder.json'
publishToPulse(exchange, routingKey, JsonOutput.toJson(payload), schema)
}
def getMachine() {
os = System.getProperty("os.name").toLowerCase().replaceAll('\\W', '-')
version = System.getProperty("os.version").toLowerCase().replaceAll('\\W', '-')
architecture = System.getProperty("os.arch")
return [
name: new URI(env.JENKINS_URL).getHost().split('\\.')[0],
platform: [os, version, architecture].join('-'),
os: os,
architecture: architecture
]
}
def getRevision() {
return sh(returnStdout: true, script: 'git rev-parse HEAD').trim()
}
def getResult() {
switch(currentBuild.result) {
case 'FAILURE':
case 'UNSTABLE':
return 'fail'
case 'SUCCESS':
case null:
return 'success'
default:
return 'unknown'
}
}
def getDateTime(timeInMillis) {
time = new Date(timeInMillis)
return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX").format(time)
}
def getJobLinks(artifactPath) {
links = [[url: env.BUILD_URL, linkText: env.BUILD_TAG, label: 'build']]
if ( artifactPath != null ) {
artifactLinks = publishToS3(artifactPath, 'net-mozaws-stage-fx-test-treeherder')
for (link in artifactLinks) {
links.add([url: link.url, linkText: link.name, label: 'artifact uploaded'])
}
}
return links
}
def getLogs(logPath) {
links = []
if ( logPath != null ) {
logLinks = publishToS3(logPath, 'net-mozaws-stage-fx-test-treeherder')
for (link in logLinks) {
links.add([url: link.url, name: link.name])
}
}
return links
}