forked from canonical/ubuntu-pro-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
284 lines (281 loc) · 12.9 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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
pipeline {
agent any
environment {
TMPDIR = "/tmp/$BUILD_TAG/"
UACLIENT_BEHAVE_JENKINS_BUILD_TAG = "${BUILD_TAG}"
UACLIENT_BEHAVE_JENKINS_CHANGE_ID = "${CHANGE_ID}"
UACLIENT_BEHAVE_BUILD_PR=1
UACLIENT_BEHAVE_CONTRACT_TOKEN = credentials('ua-contract-token')
UACLIENT_BEHAVE_AWS_ACCESS_KEY_ID = credentials('ua-aws-access-key-id')
UACLIENT_BEHAVE_AWS_SECRET_ACCESS_KEY = credentials(
'ua-aws-secret-access-key'
)
UACLIENT_BEHAVE_AZ_CLIENT_ID = credentials('ua-azure-client-id')
UACLIENT_BEHAVE_AZ_CLIENT_SECRET = credentials(
'ua-azure-client-secret'
)
UACLIENT_BEHAVE_AZ_TENANT_ID = credentials('ua-azure-tenant')
UACLIENT_BEHAVE_AZ_SUBSCRIPTION_ID = credentials(
'ua-azure-subscription-id'
)
UACLIENT_BEHAVE_CONTRACT_TOKEN_STAGING = credentials(
'ua-contract-token-staging'
)
UACLIENT_BEHAVE_CONTRACT_TOKEN_STAGING_EXPIRED = credentials(
'ua-contract-token-staging-expired'
)
JOB_SUFFIX = sh(returnStdout: true, script: "basename ${JOB_NAME}| cut -d'-' -f2").trim()
}
stages {
stage ('Setup Dependencies') {
steps {
deleteDir()
checkout scm
sh '''
python3 -m venv $TMPDIR
. $TMPDIR/bin/activate
pip install tox # for tox supporting --parallel--safe-build
pip install tox-pip-version # To freeze pip version on some tests
'''
}
}
stage("flake8") {
steps {
sh '''
set +x
tox -e flake8
'''
}
}
stage("style") {
steps {
sh '''
set +x
tox -e black -e isort
'''
}
}
stage("mypy") {
steps {
sh '''
set +x
tox -e mypy
'''
}
}
stage ('Unit Tests') {
steps {
sh '''
set +x
. $TMPDIR/bin/activate
tox --parallel--safe-build -e py3
tox --parallel--safe-build -e py3-xenial
tox --parallel--safe-build -e py3-bionic
'''
}
}
stage ('Package builds') {
parallel {
stage ('Package build: 16.04') {
environment {
BUILD_SERIES = "xenial"
SERIES_VERSION = "16.04"
PKG_VERSION = sh(returnStdout: true, script: "dpkg-parsechangelog --show-field Version").trim()
NEW_PKG_VERSION = "${PKG_VERSION}~${SERIES_VERSION}~${JOB_SUFFIX}"
ARTIFACT_DIR = "${TMPDIR}${BUILD_SERIES}"
}
steps {
sh '''
set -x
mkdir ${ARTIFACT_DIR}
cp debian/changelog ${WORKSPACE}/debian/changelog-${SERIES_VERSION}
sed -i "s/${PKG_VERSION}/${NEW_PKG_VERSION}/" ${WORKSPACE}/debian/changelog-${SERIES_VERSION}
dpkg-source -l${WORKSPACE}/debian/changelog-${SERIES_VERSION} -b .
sbuild --resolve-alternatives --nolog --verbose --dist=${BUILD_SERIES} --no-run-lintian --append-to-version=~${SERIES_VERSION} ../ubuntu-advantage-tools*${NEW_PKG_VERSION}*dsc
cp ./ubuntu-advantage-tools*${SERIES_VERSION}*.deb ${ARTIFACT_DIR}/ubuntu-advantage-tools-${BUILD_SERIES}.deb
cp ./ubuntu-advantage-pro*${SERIES_VERSION}*.deb ${ARTIFACT_DIR}/ubuntu-advantage-pro-${BUILD_SERIES}.deb
'''
}
}
stage ('Package build: 18.04') {
environment {
BUILD_SERIES = "bionic"
SERIES_VERSION = "18.04"
PKG_VERSION = sh(returnStdout: true, script: "dpkg-parsechangelog --show-field Version").trim()
NEW_PKG_VERSION = "${PKG_VERSION}~${SERIES_VERSION}~${JOB_SUFFIX}"
ARTIFACT_DIR = "${TMPDIR}${BUILD_SERIES}"
}
steps {
sh '''
set -x
mkdir ${ARTIFACT_DIR}
cp debian/changelog ${WORKSPACE}/debian/changelog-${SERIES_VERSION}
sed -i "s/${PKG_VERSION}/${NEW_PKG_VERSION}/" ${WORKSPACE}/debian/changelog-${SERIES_VERSION}
dpkg-source -l${WORKSPACE}/debian/changelog-${SERIES_VERSION} -b .
sbuild --resolve-alternatives --nolog --verbose --dist=${BUILD_SERIES} --no-run-lintian --append-to-version=~${SERIES_VERSION} ../ubuntu-advantage-tools*${NEW_PKG_VERSION}*dsc
cp ./ubuntu-advantage-tools*${SERIES_VERSION}*.deb ${ARTIFACT_DIR}/ubuntu-advantage-tools-${BUILD_SERIES}.deb
cp ./ubuntu-advantage-pro*${SERIES_VERSION}*.deb ${ARTIFACT_DIR}/ubuntu-advantage-pro-${BUILD_SERIES}.deb
'''
}
}
stage ('Package build: 20.04') {
environment {
BUILD_SERIES = "focal"
SERIES_VERSION = "20.04"
PKG_VERSION = sh(returnStdout: true, script: "dpkg-parsechangelog --show-field Version").trim()
NEW_PKG_VERSION = "${PKG_VERSION}~${SERIES_VERSION}~${JOB_SUFFIX}"
ARTIFACT_DIR = "${TMPDIR}${BUILD_SERIES}"
}
steps {
sh '''
set -x
mkdir ${ARTIFACT_DIR}
cp debian/changelog ${WORKSPACE}/debian/changelog-${SERIES_VERSION}
sed -i "s/${PKG_VERSION}/${NEW_PKG_VERSION}/" ${WORKSPACE}/debian/changelog-${SERIES_VERSION}
dpkg-source -l${WORKSPACE}/debian/changelog-${SERIES_VERSION} -b .
sbuild --resolve-alternatives --nolog --verbose --dist=${BUILD_SERIES} --no-run-lintian --append-to-version=~${SERIES_VERSION} ../ubuntu-advantage-tools*${NEW_PKG_VERSION}*dsc
cp ./ubuntu-advantage-tools*${SERIES_VERSION}*.deb ${ARTIFACT_DIR}/ubuntu-advantage-tools-${BUILD_SERIES}.deb
cp ./ubuntu-advantage-pro*${SERIES_VERSION}*.deb ${ARTIFACT_DIR}/ubuntu-advantage-pro-${BUILD_SERIES}.deb
'''
}
}
stage ('Package build: 22.04') {
environment {
BUILD_SERIES = "jammy"
SERIES_VERSION = "22.04"
PKG_VERSION = sh(returnStdout: true, script: "dpkg-parsechangelog --show-field Version").trim()
NEW_PKG_VERSION = "${PKG_VERSION}~${SERIES_VERSION}~${JOB_SUFFIX}"
ARTIFACT_DIR = "${TMPDIR}${BUILD_SERIES}"
}
steps {
sh '''
set -x
mkdir ${ARTIFACT_DIR}
cp debian/changelog ${WORKSPACE}/debian/changelog-${SERIES_VERSION}
sed -i "s/${PKG_VERSION}/${NEW_PKG_VERSION}/" ${WORKSPACE}/debian/changelog-${SERIES_VERSION}
dpkg-source -l${WORKSPACE}/debian/changelog-${SERIES_VERSION} -b .
sbuild --resolve-alternatives --nolog --verbose --dist=${BUILD_SERIES} --no-run-lintian --append-to-version=~${SERIES_VERSION} ../ubuntu-advantage-tools*${NEW_PKG_VERSION}*dsc
cp ./ubuntu-advantage-tools*${SERIES_VERSION}*.deb ${ARTIFACT_DIR}/ubuntu-advantage-tools-${BUILD_SERIES}.deb
cp ./ubuntu-advantage-pro*${SERIES_VERSION}*.deb ${ARTIFACT_DIR}/ubuntu-advantage-pro-${BUILD_SERIES}.deb
'''
}
}
}
}
stage ('Integration Tests') {
parallel {
stage("lxc 16.04") {
environment {
UACLIENT_BEHAVE_DEBS_PATH = "${TMPDIR}xenial/"
UACLIENT_BEHAVE_ARTIFACT_DIR = "artifacts/behave-lxd-16.04"
UACLIENT_BEHAVE_EPHEMERAL_INSTANCE = 1
UACLIENT_BEHAVE_SNAPSHOT_STRATEGY = 1
}
steps {
sh '''
set +x
. $TMPDIR/bin/activate
tox --parallel--safe-build -e behave-lxd-16.04 -- --tags="~slow"
'''
}
}
stage("lxc 18.04") {
environment {
UACLIENT_BEHAVE_DEBS_PATH = "${TMPDIR}bionic/"
UACLIENT_BEHAVE_ARTIFACT_DIR = "artifacts/behave-lxd-18.04"
UACLIENT_BEHAVE_EPHEMERAL_INSTANCE = 1
UACLIENT_BEHAVE_SNAPSHOT_STRATEGY = 1
}
steps {
sh '''
set +x
. $TMPDIR/bin/activate
tox --parallel--safe-build -e behave-lxd-18.04 -- --tags="~slow"
'''
}
}
stage("lxc 20.04") {
environment {
UACLIENT_BEHAVE_DEBS_PATH = "${TMPDIR}focal/"
UACLIENT_BEHAVE_ARTIFACT_DIR = "artifacts/behave-lxd-20.04"
UACLIENT_BEHAVE_EPHEMERAL_INSTANCE = 1
UACLIENT_BEHAVE_SNAPSHOT_STRATEGY = 1
}
steps {
sh '''
set +x
. $TMPDIR/bin/activate
tox --parallel--safe-build -e behave-lxd-20.04 -- --tags="~slow"
'''
}
}
stage("lxc 22.04") {
environment {
UACLIENT_BEHAVE_DEBS_PATH = "${TMPDIR}jammy/"
UACLIENT_BEHAVE_ARTIFACT_DIR = "artifacts/behave-lxd-22.04"
UACLIENT_BEHAVE_EPHEMERAL_INSTANCE = 1
UACLIENT_BEHAVE_SNAPSHOT_STRATEGY = 1
}
steps {
sh '''
set +x
. $TMPDIR/bin/activate
tox --parallel--safe-build -e behave-lxd-22.04 -- --tags="~slow"
'''
}
}
stage("lxc vm 20.04") {
environment {
UACLIENT_BEHAVE_DEBS_PATH = "${TMPDIR}focal/"
UACLIENT_BEHAVE_ARTIFACT_DIR = "artifacts/behave-vm-20.04"
UACLIENT_BEHAVE_EPHEMERAL_INSTANCE = 1
}
steps {
sh '''
set +x
. $TMPDIR/bin/activate
tox --parallel--safe-build -e behave-vm-20.04 -- --tags="~slow"
'''
}
}
stage("awspro 18.04") {
environment {
UACLIENT_BEHAVE_DEBS_PATH = "${TMPDIR}bionic/"
UACLIENT_BEHAVE_ARTIFACT_DIR = "artifacts/behave-awspro-18.04"
}
steps {
sh '''
set +x
. $TMPDIR/bin/activate
tox --parallel--safe-build -e behave-awspro-18.04 -- --tags="~slow"
'''
}
}
}
}
}
post {
always {
script {
try {
sh '''
set +x
DATE=`date -d 'now+1day' +%m/%d/%Y`
git clone https://github.com/canonical/server-test-scripts.git
python3 server-test-scripts/ubuntu-advantage-client/lxd_cleanup.py --prefix ubuntu-behave-test-$CHANGE_ID --before-date $DATE || true
'''
junit "pytest_results.xml"
junit "reports/*.xml"
} catch (Exception e) {
echo e.toString()
currentBuild.result = 'UNSTABLE'
}
try {
archiveArtifacts "artifacts/**/**/*"
} catch (Exception e) {
echo "No integration test artifacts found. Presume success."
}
}
}
}
}