forked from emartech/android-emarsys-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CloudJenkinsfile
88 lines (78 loc) · 4.83 KB
/
CloudJenkinsfile
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
@Library(['android-pipeline', 'general-pipeline']) _
properties([
parameters([
booleanParam(
name: 'DEVELOPMENT_MODE',
description: 'Use local sdk module as dependency',
defaultValue: true)])])
node('master') {
def envs = params.DEVELOPMENT_MODE ? ['DEVELOPMENT_MODE=true'] : []
withEnv(envs) {
timeout(30) {
withSlack channel: 'jenkins', {
stage('init') {
deleteDir()
git url: 'git@github.com:emartech/android-emarsys-sdk.git', branch: 'master'
}
def javaTestFileCount = sh(returnStdout: true, script: 'find . -name "*Test.java" | wc -l').trim() as Integer
def kotlinTestFileCount = sh(returnStdout: true, script: 'find . -name "*Test.kt" | wc -l').trim() as Integer
def javaTimeoutRuleCount = sh(returnStdout: true, script: 'grep -r "^\\s*public TestRule timeout = TimeoutUtils.getTimeoutRule();" . | wc -l').trim() as Integer
def kotlinTimeoutRuleCount = sh(returnStdout: true, script: 'grep -r "^\\s*val timeout: TestRule = TimeoutUtils.timeoutRule" . | wc -l').trim() as Integer
if (javaTestFileCount != javaTimeoutRuleCount) {
error("$javaTestFileCount java tests found, but only $javaTimeoutRuleCount timeout rules!")
}
if (kotlinTestFileCount != kotlinTimeoutRuleCount) {
error("$kotlinTestFileCount kotlin tests found, but only $kotlinTimeoutRuleCount timeout rules!")
}
stage('build') {
sh "./gradlew assembleAndroidTest"
}
stage('tests') {
def app = "--app 'sample/build/outputs/apk/androidTest/debug/sample-debug-androidTest.apk'"
def path = "build/outputs/apk/androidTest/debug"
def devices = [
"--device model=Nexus5,version=19,locale=en,orientation=portrait",
"--device model=shamu,version=21,locale=en,orientation=portrait",
"--device model=A0001,version=22,locale=en,orientation=portrait",
"--device model=hero2lte,version=23,locale=en,orientation=portrait",
"--device model=HWMHA,version=24,locale=en,orientation=portrait",
"--device model=G8441,version=26,locale=en,orientation=portrait",
"--device model=sailfish,version=27,locale=en,orientation=portrait",
"--device model=walleye,version=28,locale=en,orientation=portrait"
]
def createTask = { module ->
return {
sh "gcloud firebase test android run --type instrumentation --test '$module/$path/$module-debug-androidTest.apk' $app ${devices.join(' ')} --quiet --project ems-mobile-sdk"
}
}
def tasks = [
'emarsys-sdk' : createTask('emarsys-sdk'),
'core' : createTask('core'),
'core-api' : createTask('core-api'),
'mobile-engage' : createTask('mobile-engage'),
'mobile-engage-api': createTask('mobile-engage-api'),
'predict' : createTask('predict'),
'predict-api' : createTask('predict-api'),
'failFast' : false
]
parallel tasks
}
def version = sh(script: 'git describe', returnStdout: true).trim()
def statusCode = sh returnStdout: true, script: "curl -I https://dl.bintray.com/emarsys-mobile/android/com/emarsys/emarsys-sdk/$version | head -n 1 | cut -d ' ' -f2".trim()
def releaseExists = "301" == statusCode.trim()
if (version ==~ /\d+\.\d+\.\d+/ && !releaseExists) {
stage('release-bintray') {
slackMessage channel: 'jenkins', text: "Releasing Emarsys SDK $version."
sh './gradlew clean build -x lint -x test release'
slackMessage channel: 'jenkins', text: "Emarsys SDK $version released to Bintray."
}
}
stage('Deploy APK to Amazon S3') {
sh "./gradlew :sample:assembleRelease"
sh "mv sample/build/outputs/apk/release/sample-release.apk sample/build/outputs/apk/release/emarsys-sample-release.apk"
sh env.AWS_DEPLOY_COMMAND_EMARSYS
}
}
}
}
}