-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathJenkinsfile
216 lines (209 loc) · 10.1 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
def getBranchName() {
return "${GIT_BRANCH.split('/').size() > 1 ? GIT_BRANCH.split('/')[1..-1].join('/') : GIT_BRANCH}"
}
def getSimplifiedBranchName() {
return "${getBranchName().replace('/', '-')}"
}
pipeline {
environment {
BRANCH_NAME = getSimplifiedBranchName() // getBranchName()
DOCKER_IMAGE_NAME = "gounthar/jenkinsci-docker-android-base:$BRANCH_NAME"
}
agent any
options {
timestamps()
}
stages {
// stage('Checkout') {
// agent any
// steps {
// echo 'Checkout if needed'
// }
// }
stage('Static Analysis') {
parallel {
stage('Static Analysis with gradlew check') {
agent {
label 'android'
}
steps {
echo 'Run the static analysis to the code'
sh 'chmod +x ./gradlew'
sh './gradlew detekt --auto-correct'
sh 'git diff'
sh './gradlew check'
}
}
stage('Qodana') {
agent {
label 'docker'
}
steps {
sh 'docker build --tag=qodana-build-1 --file=jenkins/qodana/Dockerfile --progress=plain --output qodana-results .'
archiveArtifacts artifacts: 'qodana-results/**', allowEmptyArchive: true
}
}
}
}
stage('Compile and Code Coverage') {
parallel {
stage('Compile') {
environment {
ANDROID_PUBLISHER_CREDENTIALS = credentials('android-publisher-credentials')
}
agent {
label 'android'
}
steps {
script {
sh 'echo "Compile the source code"'
sh 'env | grep $HOME'
sh 'chmod +x ./gradlew'
sh './gradlew build'
sh 'ls -artl /home/jenkins/.gradle/wrapper/dists'
sh 'find /home/jenkins/ -name "gradle-7.3.3-bin.zip" -exec ls {} \\;'
sh './gradlew :app:bundleDebug :app:bundleRelease'
}
}
}
stage('Code Coverage') {
environment {
ANDROID_PUBLISHER_CREDENTIALS = credentials('android-publisher-credentials')
}
agent {
label 'android'
}
steps {
script {
sh 'echo "Ensure that the code coverage is not just wishful thinking"'
sh 'chmod +x ./gradlew'
sh 'chmod +x ./gradlew && ./gradlew jacocoTestReport'
sh 'find build -name "*eports*"'
}
}
}
}
}
stage('Security Check') {
agent any
steps {
echo 'Run the security check against the application'
echo 'Something like dependency check or dependabot'
}
}
stage('Run Unit Tests') {
agent {
label 'android'
}
steps {
echo 'Run unit tests from the source code'
sh 'chmod +x gradlew && ./gradlew test'
}
}
stage('Run Instrumented Tests') {
environment {
PUBLIC_IP = "${env.PUBLIC_IP}"
STF_HOST_NAME = "${env.STF_HOST_NAME}"
STF_API_TOKEN = credentials('stf-api-token')
ANDROID_VERSION = '11'
}
agent {
label 'android'
}
steps {
lock('MyEmulator') {
echo 'Run only instrumented tests from the source code'
// We don't have any device connected yet
// sh 'adb connect emulator:5555'
sh '/usr/local/stf/android-stf-api.py --token $STF_API_TOKEN --version $ANDROID_VERSION connect'
// sh 'adb connect ${PUBLIC_IP}:7401'
// sh 'sleep 10'
// sh 'adb connect ${PUBLIC_IP}:7401'
sh 'adb devices'
// sh 'adb -s ${PUBLIC_IP}:7401 wait-for-device shell \'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done;\''
// sh 'adb -s ${STF_HOST_NAME}:7401 shell am start -n "io.jenkins.mobile.example.myfirstbuiltbyjenkinsapplication.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER'
sh 'chmod +x ./gradlew &&./gradlew connectedAndroidTest'
sh '/usr/local/stf/android-stf-api.py --token $STF_API_TOKEN --version $ANDROID_VERSION disconnect'
}
}
post {
always {
lock('MyEmulator') {
sh '/usr/local/stf/android-stf-api.py --token $STF_API_TOKEN --version $ANDROID_VERSION disconnect'
}
}
}
}
stage('Publishing Artifacts on Jenkins/GitHub/GooglePlayStore') {
parallel {
stage('Publish Artifacts') {
agent any
steps {
echo 'Save the assemblies generated from the compilation'
archiveArtifacts artifacts: 'app/build/outputs/apk/**/*.apk', allowEmptyArchive: true
archiveArtifacts artifacts: 'app/build/outputs/bundle/**/*.aab', allowEmptyArchive: true
archiveArtifacts artifacts: 'app/build/reports/*xml', allowEmptyArchive: true
archiveArtifacts artifacts: 'app/build/reports/*html', allowEmptyArchive: true
archiveArtifacts artifacts: 'app/build/reports/**/*.xml', allowEmptyArchive: true
archiveArtifacts artifacts: 'app/build/reports/**/*.html', allowEmptyArchive: true
archiveArtifacts artifacts: 'app/build/outputs/androidTest-results/connected/*.pb', allowEmptyArchive: true
publishHTML([allowMissing: true, alwaysLinkToLastBuild: false, keepAll: false, reportDir: 'app/build/reports', reportFiles: 'lint-results-debug.html', reportName: 'Lint Report', reportTitles: ''])
publishHTML([allowMissing: true, alwaysLinkToLastBuild: false, keepAll: false, reportDir: 'app/build/reports/detekt', reportFiles: 'detekt.html', reportName: 'Detekt Report', reportTitles: ''])
publishHTML([allowMissing: true, alwaysLinkToLastBuild: false, keepAll: false, reportDir: 'app/build/reports/spotbugs', reportFiles: 'debug.html', reportName: 'Spotbugs Debug Report', reportTitles: ''])
publishHTML([allowMissing: true, alwaysLinkToLastBuild: false, keepAll: false, reportDir: 'app/build/reports/spotbugs', reportFiles: 'release.html', reportName: 'Spotbugs Release Report', reportTitles: ''])
publishHTML([allowMissing: true, alwaysLinkToLastBuild: false, keepAll: false, reportDir: 'app/build/reports/tests/testDebugUnitTest', reportFiles: 'index.html', reportName: 'Test Debug Unit Testing Report', reportTitles: ''])
publishHTML([allowMissing: true, alwaysLinkToLastBuild: false, keepAll: false, reportDir: 'app/build/reports/tests/testReleaseUnitTest', reportFiles: 'index.html', reportName: 'Test Release Unit Testing', reportTitles: ''])
}
}
stage('Invoke Pipeline PublishAppToGitHubAndGoogle') {
steps {
build wait: false, propagate: false, job: 'PublishAppToGitHubAndGoogle'
}
}
}
}
}
// post {
// always {
// // junit '/app/build/jacoco/*.xml'
// // junit '/app/build/test-results/**/*.xml'
// // junit '/app/build/reports/tests/*.xml'
// // junit '/app/build/reports/*.xml'
// // junit '/app/build/reports/detekt/*.xml'
// // junit '/app/build/reports/spotbugs/*.xml'
// testResultsAggregator jobs:[[jobName: 'My CI Job1'], [jobName: 'My CI Job2'], [jobName: 'My CI Job3']]
// }
// }
}
void releaseAlreadyExist(config) {
GITHUB_CREDENTIALS_PSW = credentials('github-app-android').toString()
echo $GITHUB_CREDENTIALS_PSW
}
void createRelease() {
sh (
script: 'chmod +x ./jenkins/create-release.sh && ./jenkins/create-release.sh',
returnStdout: true
)
}
void createGooglePlayStoreRelease() {
sh (
script: 'chmod +x ./jenkins/create-gps-release.sh && ./jenkins/create-gps-release.sh',
returnStdout: true
)
}
// testResultsAggregator columns: 'Job, Build, Status, Percentage, Total, Pass, Fail',
// recipientsList: '[email protected],[email protected]',
// outOfDateResults: '10',
// sortresults: 'Job Name',
// subject: 'Test Results'
// jobs: [
// // Group with 2 Jobs
// [jobName: 'My CI Job1', jobFriendlyName: 'Job 1', groupName: 'TeamA'],
// [jobName: 'My CI Job2', jobFriendlyName: 'Job 2', groupName: 'TeamA'],
// // jobFriendlyName is optional
// [jobName: 'My CI Job3', groupName: 'TeamB'],
// [jobName: 'My CI Job4', groupName: 'TeamB'],
// // No Groups, groupName is optional
// [jobName: 'My CI Job6'],
// [jobName: 'My CI Job7']
// ]