-
Notifications
You must be signed in to change notification settings - Fork 2
/
Jenkinsfile
219 lines (214 loc) · 8.84 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
@Library("[email protected]") _
/*
Runs the following steps in parallel and reports results to GitHub:
- Lint using flake8
- Run Python 2.7 unit tests in tox
- Run Python 3 unit tests in tox
- Build Debian packages for supported Ubuntu versions
If these steps succeed and the master branch is being built, wheels and debs are uploaded to PyPI and the
R&D Debian mirrors.
Optionally you can set FORCE_PYUPLOAD to force upload to PyPI, and FORCE_DEBUPLOAD to force Debian package
upload on non-master branches.
*/
pipeline {
agent {
label "ubuntu&&apmm-slave"
}
options {
ansiColor('xterm') // Add support for coloured output
buildDiscarder(logRotator(numToKeepStr: '10')) // Discard old builds
}
parameters {
booleanParam(name: "FORCE_PYUPLOAD", defaultValue: false, description: "Force Python artifact upload")
booleanParam(name: "FORCE_DEBUPLOAD", defaultValue: false, description: "Force Debian package upload")
}
triggers {
upstream (upstreamProjects: "apmm-repos/nmos-common/master")
}
environment {
http_proxy = "http://www-cache.rd.bbc.co.uk:8080"
https_proxy = "http://www-cache.rd.bbc.co.uk:8080"
}
stages {
stage("Clean Environment") {
steps {
sh 'git clean -dfx'
}
}
stage ("Tests") {
parallel {
stage ("Unit Tests") {
stages {
stage ("Python 2.7 Unit Tests") {
steps {
script {
env.py27_result = "FAILURE"
}
bbcGithubNotify(context: "tests/py27", status: "PENDING")
// Use a workdirectory in /tmp to avoid shebang length limitation
withBBCRDPythonArtifactory {
sh 'tox -e py27 --recreate --workdir /tmp/$(basename ${WORKSPACE})/tox-py27'
}
script {
env.py27_result = "SUCCESS" // This will only run if the sh above succeeded
}
}
post {
always {
bbcGithubNotify(context: "tests/py27", status: env.py27_result)
}
}
}
stage ("Python 3 Unit Tests") {
steps {
script {
env.py3_result = "FAILURE"
}
bbcGithubNotify(context: "tests/py3", status: "PENDING")
// Use a workdirectory in /tmp to avoid shebang length limitation
withBBCRDPythonArtifactory {
sh 'tox -e py3 --recreate --workdir /tmp/$(basename ${WORKSPACE})/tox-py3'
}
script {
env.py3_result = "SUCCESS" // This will only run if the sh above succeeded
}
}
post {
always {
bbcGithubNotify(context: "tests/py3", status: env.py3_result)
}
}
}
}
}
}
}
stage ("Debian Source Build") {
steps {
script {
env.debSourceBuild_result = "FAILURE"
}
bbcGithubNotify(context: "deb/sourceBuild", status: "PENDING")
sh 'python ./setup.py sdist'
sh 'make dsc'
bbcPrepareDsc()
stash(name: "deb_dist", includes: "deb_dist/*")
script {
env.debSourceBuild_result = "SUCCESS" // This will only run if the steps above succeeded
}
}
post {
always {
bbcGithubNotify(context: "deb/sourceBuild", status: env.debSourceBuild_result)
}
}
}
stage ("Build Package") {
parallel{
stage ("Build Deb with pbuilder") {
steps {
script {
env.pbuilder_result = "FAILURE"
}
bbcGithubNotify(context: "deb/packageBuild", status: "PENDING")
// Build for all supported platforms and extract results into workspace
bbcParallelPbuild(
stashname: "deb_dist",
dists: bbcGetSupportedUbuntuVersions(),
arch: "amd64")
script {
env.pbuilder_result = "SUCCESS" // This will only run if the steps above succeeded
}
}
post {
success {
archiveArtifacts artifacts: "_result/**"
}
always {
bbcGithubNotify(context: "deb/packageBuild", status: env.pbuilder_result)
}
}
}
}
}
stage ("Upload Package") {
// Duplicates the when clause of each upload so blue ocean can nicely display when stage skipped
when {
anyOf {
expression { return params.FORCE_PYUPLOAD }
expression { return params.FORCE_DEBUPLOAD }
expression {
bbcShouldUploadArtifacts(branches: ["master"])
}
}
}
parallel {
stage ("Upload to PyPI") {
when {
anyOf {
expression { return params.FORCE_PYUPLOAD }
expression {
bbcShouldUploadArtifacts(branches: ["master"])
}
}
}
steps {
script {
env.pypiUpload_result = "FAILURE"
}
bbcGithubNotify(context: "pypi/upload", status: "PENDING")
sh 'rm -rf dist/*'
bbcMakeGlobalWheel("py27")
bbcMakeGlobalWheel("py3")
bbcTwineUpload(toxenv: "py3", pypi: true)
script {
env.pypiUpload_result = "SUCCESS" // This will only run if the steps above succeeded
}
}
post {
always {
bbcGithubNotify(context: "pypi/upload", status: env.pypiUpload_result)
}
}
}
stage ("upload deb") {
when {
anyOf {
expression { return params.FORCE_DEBUPLOAD }
expression {
bbcShouldUploadArtifacts(branches: ["master"])
}
}
}
steps {
script {
env.debUpload_result = "FAILURE"
}
bbcGithubNotify(context: "deb/upload", status: "PENDING")
script {
for (def dist in bbcGetSupportedUbuntuVersions()) {
bbcDebUpload(sourceFiles: "_result/${dist}-amd64/*",
removePrefix: "_result/${dist}-amd64",
dist: "${dist}",
apt_repo: "ap/python")
}
}
script {
env.debUpload_result = "SUCCESS" // This will only run if the steps above succeeded
}
}
post {
always {
bbcGithubNotify(context: "deb/upload", status: env.debUpload_result)
}
}
}
}
}
}
post {
always {
bbcSlackNotify()
}
}
}