forked from cloudant/sync-android
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
134 lines (124 loc) · 5.7 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
#!groovy
/*
* Copyright © 2017 IBM Corp. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/
def runTests(testEnv, isAndroid) {
node(isAndroid ? 'android' : null) {
// make a copy of the env
def localTestEnv = []
localTestEnv.addAll(testEnv)
if (isAndroid) {
// Android tests run on static hardware so clean the dir
deleteDir()
localTestEnv.add('GRADLE_TARGET=-b AndroidTest/build.gradle uploadFixtures connectedCheck')
} else {
localTestEnv.add('GRADLE_TARGET=integrationTest')
}
// Unstash the built content
unstash name: 'built'
//Set up the environment and run the tests
withEnv(localTestEnv) {
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: env.CREDS_ID, usernameVariable: 'DB_USER', passwordVariable: 'DB_PASSWORD']]) {
try {
sh './gradlew -Dtest.with.specified.couch=true -Dtest.couch.username=$DB_USER -Dtest.couch.password=$DB_PASSWORD -Dtest.couch.host=$DB_HOST -Dtest.couch.port=$DB_PORT -Dtest.couch.http=$DB_HTTP -Dtest.couch.ignore.compaction=$DB_IGNORE_COMPACTION -Dtest.couch.ignore.auth.headers=true $GRADLE_TARGET'
} finally {
junit '**/build/**/*.xml'
if (isAndroid) {
// Collect the device log
archiveArtifacts artifacts: '**/build/**/*logcat.log'
}
}
}
}
}
}
stage('Build') {
// Checkout, build and assemble the source and doc
node {
checkout scm
sh './gradlew clean assemble'
stash name: 'built'
}
}
stage('QA') {
// Define the matrix environments
def CLOUDANT_ENV = ['TEST_ENV_NAME=Cloudant_Test','DB_HTTP=https', 'DB_HOST=clientlibs-test.cloudant.com', 'DB_PORT=443', 'DB_IGNORE_COMPACTION=true', 'CREDS_ID=clientlibs-test']
def COUCH1_6_ENV = ['TEST_ENV_NAME=CouchDB1_6_Test','DB_HTTP=http', 'DB_HOST=cloudantsync002.bristol.uk.ibm.com', 'DB_PORT=5984', 'DB_IGNORE_COMPACTION=false', 'CREDS_ID=couchdb']
def COUCH2_0_ENV = ['TEST_ENV_NAME=CouchDB2_0_Test','DB_HTTP=http', 'DB_HOST=cloudantsync002.bristol.uk.ibm.com', 'DB_PORT=5985', 'DB_IGNORE_COMPACTION=true', 'CREDS_ID=couchdb']
def CLOUDANT_LOCAL_ENV = ['TEST_ENV_NAME=CloudantLocal_Test','DB_HTTP=http', 'DB_HOST=cloudantsync002.bristol.uk.ibm.com', 'DB_PORT=8081', 'DB_IGNORE_COMPACTION=true', 'CREDS_ID=couchdb']
// Standard builds do Findbugs and test sync-android for Android and Java against Cloudant
def axes = [
Findbugs : {
node {
unstash name: 'built'
// findBugs
try {
sh './gradlew -Dfindbugs.xml.report=true findbugsMain'
} finally {
step([$class: 'FindBugsPublisher', pattern: '**/build/reports/findbugs/*.xml'])
}
}
},
Java_Cloudant : {
runTests(CLOUDANT_ENV, false)
},
Android_Cloudant: {
runTests(CLOUDANT_ENV, true)
}
]
// For the master branch, add additional axes to the coverage matrix for Couch 1.6, 2.0
// and Cloudant Local
if (env.BRANCH_NAME == "master") {
axes.putAll(
Java_Couch1_6: {
runTests(COUCH1_6_ENV, false)
},
Android_Couch1_6: {
runTests(COUCH1_6_ENV, true)
},
Java_Couch2_0: {
runTests(COUCH2_0_ENV, false)
},
Android_Couch2_0: {
runTests(COUCH2_0_ENV, true)
},
Java_CloudantLocal: {
runTests(CLOUDANT_LOCAL_ENV, false)
},
Android_CloudantLocal: {
runTests(CLOUDANT_LOCAL_ENV, true)
}
)
}
// Run the required axes in parallel
parallel(axes)
}
// Publish the master branch
stage('Publish') {
if (env.BRANCH_NAME == "master") {
node {
unstash name: 'built'
// read the version name and determine if it is a release build
version = readFile('VERSION').trim()
isReleaseVersion = !version.toUpperCase(Locale.ENGLISH).contains("SNAPSHOT")
// Upload using the ossrh creds (upload destination logic is in build.gradle)
withCredentials([usernamePassword(credentialsId: 'ossrh-creds', passwordVariable: 'OSSRH_PASSWORD', usernameVariable: 'OSSRH_USER'), usernamePassword(credentialsId: 'signing-creds', passwordVariable: 'KEY_PASSWORD', usernameVariable: 'KEY_ID'), file(credentialsId: 'signing-key', variable: 'SIGNING_FILE')]) {
sh './gradlew -Dsigning.keyId=$KEY_ID -Dsigning.password=$KEY_PASSWORD -Dsigning.secretKeyRingFile=$SIGNING_FILE -DossrhUsername=$OSSRH_USER -DossrhPassword=$OSSRH_PASSWORD upload'
}
gitTagAndPublish {
isDraft=true
releaseApiUrl='https://api.github.com/repos/cloudant/sync-android/releases'
}
}
}
}