forked from mozilla/treeherder-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
153 lines (145 loc) · 3.44 KB
/
Jenkinsfile
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
import groovy.json.JsonOutput
/** Tox environment */
def environment = 'tests'
/** Map of desired capabilities */
def capabilities = [
browserName: 'Firefox',
version: '47.0',
platform: 'Windows 7'
]
/** Write capabilities to JSON file
*
* @param desiredCapabilities capabilities to include in the file
*/
def writeCapabilities(desiredCapabilities) {
def defaultCapabilities = [
build: env.BUILD_TAG,
public: 'public restricted'
]
def capabilities = defaultCapabilities.clone()
capabilities.putAll(desiredCapabilities)
def json = JsonOutput.toJson([capabilities: capabilities])
writeFile file: 'capabilities.json', text: json
}
/** Run Tox
*
* @param environment test environment to run
*/
def runTox(environment) {
def processes = env.PYTEST_PROCESSES ?: 'auto'
try {
wrap([$class: 'AnsiColorBuildWrapper']) {
withCredentials([[
$class: 'StringBinding',
credentialsId: 'SAUCELABS_API_KEY',
variable: 'SAUCELABS_API_KEY']]) {
withEnv(["PYTEST_ADDOPTS=${PYTEST_ADDOPTS} " +
"-n=${processes} " +
"--driver=SauceLabs " +
"--variables=capabilities.json " +
"--color=yes"]) {
sh "tox -e ${environment}"
}
}
}
} catch(err) {
currentBuild.result = 'FAILURE'
throw err
} finally {
dir('results') {
stash environment
}
}
}
/** Send a notice to #fxtest-alerts on irc.mozilla.org with the build result
*
* @param result outcome of build
*/
def ircNotification(result) {
def nick = "fxtest${BUILD_NUMBER}"
def channel = '#fx-test-alerts'
result = result.toUpperCase()
def message = "Project ${JOB_NAME} build #${BUILD_NUMBER}: ${result}: ${BUILD_URL}"
node {
sh """
(
echo NICK ${nick}
echo USER ${nick} 8 * : ${nick}
sleep 5
echo "JOIN ${channel}"
echo "NOTICE ${channel} :${message}"
echo QUIT
) | openssl s_client -connect irc.mozilla.org:6697
"""
}
}
stage('Checkout') {
node {
timestamps {
deleteDir()
checkout scm
stash 'workspace'
}
}
}
stage('Lint') {
node {
timestamps {
deleteDir()
unstash 'workspace'
sh 'tox -e flake8'
}
}
}
try {
stage('Test') {
node {
timeout(time: 1, unit: 'HOURS') {
timestamps {
deleteDir()
unstash 'workspace'
try {
writeCapabilities(capabilities)
runTox(environment)
} catch(err) {
currentBuild.result = 'FAILURE'
throw err
} finally {
dir('results') {
stash environment
}
}
}
}
}
}
} catch(err) {
currentBuild.result = 'FAILURE'
ircNotification(currentBuild.result)
mail(
body: "${BUILD_URL}",
from: "firefox-test-engineering@mozilla.com",
replyTo: "firefox-test-engineering@mozilla.com",
subject: "Build failed in Jenkins: ${JOB_NAME} #${BUILD_NUMBER}",
to: "fte-ci@mozilla.com")
throw err
} finally {
stage('Results') {
node {
deleteDir()
sh 'mkdir results'
dir('results') {
unstash environment
}
publishHTML(target: [
allowMissing: false,
alwaysLinkToLastBuild: true,
keepAll: true,
reportDir: 'results',
reportFiles: "${environment}.html",
reportName: 'HTML Report'])
junit 'results/*.xml'
archiveArtifacts 'results/*'
}
}
}