-
Notifications
You must be signed in to change notification settings - Fork 100
/
Jenkinsfile
162 lines (155 loc) · 6.2 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
pipeline {
agent {
label "ec2-android"
}
triggers {
cron('0 0 * * *')
}
options {
buildDiscarder(logRotator(daysToKeepStr: '5'))
timeout(time: 50)
disableConcurrentBuilds(abortPrevious: true)
}
stages {
stage('Change to JAVA 17') {
steps {
script {
echo 'Changing JAVA version to 17'
sh 'sudo update-alternatives --set java /usr/lib/jvm/java-17-openjdk-amd64/bin/java'
env.JAVA_HOME = '/usr/lib/jvm/java-17-openjdk-amd64'
}
}
}
stage('Lint Check') {
steps {
script {
echo 'Running Ktlint'
sh './gradlew ktlintCheck'
}
}
}
stage('Unit tests') {
environment {
ANDROID_HOME = '/opt/android-sdk'
}
steps {
script {
echo 'Running unit tests on app module'
sh './gradlew :app:testDhisDebugUnitTest --stacktrace --no-daemon'
echo 'Running unit tests on all other modules'
sh './gradlew testDebugUnitTest --stacktrace --no-daemon'
}
}
}
stage('Build Test APKs') {
steps {
script {
echo 'Building UI APKs'
sh './gradlew :app:assembleDhisUITestingDebug :app:assembleDhisUITestingDebugAndroidTest :compose-table:assembleAndroidTest :form:assembleAndroidTest'
}
}
}
stage('Run tests') {
parallel {
stage('Deploy and run Form Tests') {
environment {
BROWSERSTACK = credentials('android-browserstack')
form_apk = sh(returnStdout: true, script: 'find form/build/outputs -iname "*.apk" | sed -n 1p')
form_apk_path = "${env.WORKSPACE}/${form_apk}"
buildTag = "${env.GIT_BRANCH} - form"
}
steps {
dir("${env.WORKSPACE}/scripts"){
script {
echo 'Browserstack deployment and running Form module tests'
sh 'chmod +x browserstackJenkinsForm.sh'
sh './browserstackJenkinsForm.sh'
}
}
}
}
stage('Deploy compose-table module Tests') {
environment {
BROWSERSTACK = credentials('android-browserstack')
compose_table_apk = sh(returnStdout: true, script: 'find compose-table/build/outputs -iname "*.apk" | sed -n 1p')
compose_table_apk_path = "${env.WORKSPACE}/${compose_table_apk}"
buildTag = "${env.GIT_BRANCH} - table"
}
steps {
dir("${env.WORKSPACE}/scripts"){
script {
echo 'Browserstack deployment and running compose-table module tests'
sh 'chmod +x browserstackJenkinsCompose.sh'
sh './browserstackJenkinsCompose.sh'
}
}
}
}
stage('Deploy and Run UI Tests') {
environment {
BROWSERSTACK = credentials('android-browserstack')
app_apk = sh(returnStdout: true, script: 'find app/build/outputs -iname "*.apk" | sed -n 1p')
test_apk = sh(returnStdout: true, script: 'find app/build/outputs -iname "*.apk" | sed -n 2p')
app_apk_path = "${env.WORKSPACE}/${app_apk}"
test_apk_path = "${env.WORKSPACE}/${test_apk}"
buildTag = "${env.GIT_BRANCH}"
}
steps {
dir("${env.WORKSPACE}/scripts"){
script {
echo 'Browserstack deployment and running tests'
sh 'chmod +x browserstackJenkins.sh'
sh './browserstackJenkins.sh'
}
}
}
}
}
}
stage('JaCoCo report') {
steps {
script {
echo 'Running JaCoCo report on app module'
sh './gradlew jacocoReport --stacktrace --no-daemon'
}
}
}
stage('Sonarqube') {
environment {
GIT_BRANCH = "${env.GIT_BRANCH}"
// Jenkinsfile considers empty value ('') as null
GIT_BRANCH_DEST = "${env.CHANGE_TARGET == null ? '' : env.CHANGE_TARGET}"
PULL_REQUEST = "${env.CHANGE_ID == null ? '' : env.CHANGE_ID }"
SONAR_TOKEN = credentials('android-sonarcloud-token')
}
steps {
script {
echo 'Running Sonarqube'
sh 'chmod +x ./scripts/sonarqube.sh'
sh './scripts/sonarqube.sh'
}
}
}
}
post {
success {
sendNotification(env.GIT_BRANCH, '*Build Succeeded*\n', 'good')
}
failure {
sendNotification(env.GIT_BRANCH, '*Build Failed*\n', 'bad')
}
}
}
def sendNotification(String branch, String messagePrefix, String color){
if( !branch.startsWith('PR') ){
slackSend channel: '#android-capture-app-ci', color: color, message: messagePrefix+ custom_msg()
}
}
def custom_msg(){
def BUILD_URL= env.BUILD_URL
def JOB_NAME = env.JOB_NAME
def BUILD_ID = env.BUILD_ID
def BRANCH_NAME = env.GIT_BRANCH
def JENKINS_LOG= "*Job:* $JOB_NAME\n *Branch:* $BRANCH_NAME\n *Build Number:* $BUILD_NUMBER (<${BUILD_URL}|Open>)"
return JENKINS_LOG
}