forked from victorwon/mopub-android-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
165 lines (157 loc) · 8.18 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
#!/usr/bin/env groovy
def androidAutomationProjectName = "mopub-android-automation"
pipeline {
agent any
environment {
ANDROID_HOME = '/Users/jenkins/Library/Android/sdk'
ANDROID_BUILD_TOOLS_VERSION = '30.0.2'
APK_INTERNAL_RELEASE_SIGNED = 'mopub-sample/build/outputs/apk/internal/release/mopub-sample-internal-release-signed.apk'
APK_INTERNAL_RELEASE_UNSIGNED = 'mopub-sample/build/outputs/apk/internal/release/mopub-sample-internal-release-unsigned.apk'
APK_INTERNAL_RELEASE_UNSIGNED_ALIGNED = 'mopub-sample/build/outputs/apk/internal/release/mopub-sample-internal-release-unsigned-aligned.apk'
APK_EXTERNAL_RELEASE_SIGNED = 'mopub-sample/build/outputs/apk/external/release/mopub-sample-external-release-signed.apk'
APK_EXTERNAL_RELEASE_UNSIGNED = 'mopub-sample/build/outputs/apk/external/release/mopub-sample-external-release-unsigned.apk'
APK_EXTERNAL_RELEASE_UNSIGNED_ALIGNED = 'mopub-sample/build/outputs/apk/external/release/mopub-sample-external-release-unsigned-aligned.apk'
projectName = """${
sh(script: 'IFS="/" read -ra TOKENS <<< "${JOB_NAME}"; echo ${TOKENS[0]}', returnStdout: true).trim()
}"""
PARSED_JOB_NAME = URLDecoder.decode(env.JOB_NAME, 'UTF-8')
}
stages {
stage('Build AARs') {
steps {
echo "Building the MoPub SDK AARs"
sh '''
#!/bin/bash
./gradlew clean
./gradlew :mopub-sdk:build -x test
./gradlew :mopub-sdk:mopub-sdk-base:build -x test
./gradlew :mopub-sdk:mopub-sdk-banner:build -x test
./gradlew :mopub-sdk:mopub-sdk-fullscreen:build -x test
./gradlew :mopub-sdk:mopub-sdk-native-static:build -x test
'''
}
}
stage('Build APKs') {
steps {
echo "Building the MoPub Sample App"
sh '''
#!/bin/bash
./gradlew :mopub-sample:build -x test
'''
}
}
stage('Test') {
parallel {
stage('Running the MoPub SDK Unit Tests') {
steps {
echo "Running the MoPub SDK Unit Tests"
sh '''
#!/bin/bash
./gradlew :mopub-sdk:test -x build
'''
}
}
stage('External Android automation tests') {
steps {
echo "External Automation Tests are running - ${PARSED_JOB_NAME}"
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
sh '''
#!/bin/bash
chmod +x scripts/private/android.sh
scripts/private/android.sh
'''
}
}
}
stage('Internal Android automation tests') {
steps {
echo "Internal Automation Tests are running - ${PARSED_JOB_NAME}"
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
sh '''
#!/bin/bash
chmod +x scripts/private/androidRT.sh
scripts/private/androidRT.sh
'''
}
}
}
}
}
stage('Publish Test Results') {
steps {
script {
publishHTML (target : [allowMissing: true,
alwaysLinkToLastBuild: false,
keepAll: true,
reportDir: 'mopub-sample/build/reports/androidTests/connected/flavors/EXTERNAL',
reportFiles: '**/*',
reportName: 'Android EXTERNAL Automation Test Results'])
publishHTML (target : [allowMissing: true,
alwaysLinkToLastBuild: false,
keepAll: true,
reportDir: 'mopub-sample/build/reports/androidTests/connected/flavors/INTERNAL',
reportFiles: '**/*',
reportName: 'Android INTERNAL Automation Test Results'])
junit 'mopub-sdk/build/test-results/**/*.xml'
}
}
}
stage('Sign apk') {
parallel {
stage('Internal') {
steps {
script {
// Remove old APKs generated by this step
sh 'rm -f $APK_INTERNAL_RELEASE_SIGNED'
sh 'rm -f $APK_INTERNAL_RELEASE_UNSIGNED_ALIGNED'
// If something in this step fails, allow the pipeline to continue
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
// Create unsigned and aligned APK from unsigned APK
sh '$ANDROID_HOME/build-tools/$ANDROID_BUILD_TOOLS_VERSION/zipalign -v -p 4 $APK_INTERNAL_RELEASE_UNSIGNED $APK_INTERNAL_RELEASE_UNSIGNED_ALIGNED'
// Use credentials to create signed APK from unsigned and aligned APK
withCredentials([string(credentialsId: 'android_store_key_pass', variable: 'JKS_PASS')]) {
sh '$ANDROID_HOME/build-tools/$ANDROID_BUILD_TOOLS_VERSION/apksigner sign --ks ~/google_play_key.jks --ks-pass pass:$JKS_PASS --out $APK_INTERNAL_RELEASE_SIGNED $APK_INTERNAL_RELEASE_UNSIGNED_ALIGNED'
}
}
}
}
}
stage('External') {
steps {
script {
// Remove old APKs generated by this step
sh 'rm -f $APK_EXTERNAL_RELEASE_SIGNED'
sh 'rm -f $APK_EXTERNAL_RELEASE_UNSIGNED_ALIGNED'
// If something in this step fails, allow the pipeline to continue
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
// Create unsigned and aligned APK from unsigned APK
sh '$ANDROID_HOME/build-tools/$ANDROID_BUILD_TOOLS_VERSION/zipalign -v -p 4 $APK_EXTERNAL_RELEASE_UNSIGNED $APK_EXTERNAL_RELEASE_UNSIGNED_ALIGNED'
// Use credentials to create signed APK from unsigned and aligned APK
withCredentials([string(credentialsId: 'android_store_key_pass', variable: 'JKS_PASS')]) {
sh '$ANDROID_HOME/build-tools/$ANDROID_BUILD_TOOLS_VERSION/apksigner sign --ks ~/google_play_key.jks --ks-pass pass:$JKS_PASS --out $APK_EXTERNAL_RELEASE_SIGNED $APK_EXTERNAL_RELEASE_UNSIGNED_ALIGNED'
}
}
}
}
}
}
}
stage('Archive') {
steps {
script {
archiveArtifacts artifacts: 'mopub-sample/build/outputs/**/*.apk', excludes: 'mopub-sample/build/outputs/**/*unsigned.apk, mopub-sample/build/outputs/**/*aligned.apk', onlyIfSuccessful: true
archiveArtifacts artifacts: 'mopub-sdk/build/outputs/aar/mopub-sdk-*.aar', onlyIfSuccessful: true
archiveArtifacts artifacts: 'mopub-sdk/mopub-sdk-*/build/outputs/aar/mopub-sdk-*.aar', onlyIfSuccessful: true
}
}
}
}
post {
fixed {
slackSend color: 'GREEN', message: "<${env.BUILD_URL}|${PARSED_JOB_NAME} #${env.BUILD_NUMBER}> has succeeded."
}
failure {
slackSend color: 'RED', message: "Attention @here <${env.BUILD_URL}|${PARSED_JOB_NAME} #${env.BUILD_NUMBER}> has failed."
}
}
}