forked from cloudant/python-cloudant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
81 lines (77 loc) · 2.28 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
def getEnvForSuite(suiteName) {
// Base environment variables
def envVars = [
"CLOUDANT_ACCOUNT=$DB_USER",
"RUN_CLOUDANT_TESTS=1",
"SKIP_DB_UPDATES=1" // Disable pending resolution of case 71610
]
// Add test suite specific environment variables
switch(suiteName) {
case 'basic':
envVars.add("RUN_BASIC_AUTH_TESTS=1")
break
case 'iam':
// Setting IAM_API_KEY forces tests to run using an IAM enabled client.
envVars.add("IAM_API_KEY=$DB_IAM_API_KEY")
break
case 'cookie':
case 'simplejson':
break
default:
error("Unknown test suite environment ${suiteName}")
}
return envVars
}
def setupPythonAndTest(pythonVersion, testSuite) {
node {
// Unstash the source on this node
unstash name: 'source'
// Set up the environment and test
withCredentials([usernamePassword(credentialsId: 'clientlibs-test', usernameVariable: 'DB_USER', passwordVariable: 'DB_PASSWORD'),
string(credentialsId: 'clientlibs-test-iam', variable: 'DB_IAM_API_KEY')]) {
withEnv(getEnvForSuite("${testSuite}")) {
try {
sh """
virtualenv tmp -p ${pythonVersion.startsWith('3') ? "python3" : "python"}
. ./tmp/bin/activate
python --version
pip install -r requirements.txt
pip install -r test-requirements.txt
${'simplejson'.equals(testSuite) ? 'pip install simplejson' : ''}
pylint ./src/cloudant
nosetests -A 'not db or (db is "cloudant" or "cloudant" in db)' -w ./tests/unit --with-xunit
"""
} finally {
// Load the test results
junit 'nosetests.xml'
}
}
}
}
}
// Start of build
stage('Checkout'){
// Checkout and stash the source
node{
checkout scm
stash name: 'source'
}
}
stage('Test'){
def py2 = '2'
def py3 = '3'
def axes = [:]
[py2, py3].each { version ->
['basic','cookie','iam'].each { auth ->
axes.put("Python${version}-${auth}", {setupPythonAndTest(version, auth)})
}
}
axes.put("Python${py3}-simplejson", {setupPythonAndTest(py3, 'simplejson')})
parallel(axes)
}
stage('Publish') {
gitTagAndPublish {
isDraft=true
releaseApiUrl='https://api.github.com/repos/cloudant/python-cloudant/releases'
}
}