forked from dhis2/dhis2-android-capture-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
117 lines (112 loc) · 4.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
pipeline {
agent {
label "ec2-android"
}
options {
buildDiscarder(logRotator(daysToKeepStr: '5'))
timeout(time: 50)
}
stages{
stage('Ktlint') {
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 testDhisDebugUnitTestCoverage'
echo 'Running unit tests on all other modules'
sh './gradlew testDebugUnitTest'
}
}
}
stage('Sonarqube') {
environment {
BITRISE_GIT_BRANCH = "$env.GIT_BRANCH"
BITRISEIO_GIT_BRANCH_DEST = "${env.CHANGE_TARGET == null ? env.GIT_BRANCH : env.CHANGE_TARGET}"
BITRISE_PULL_REQUEST = "${env.CHANGE_ID == null ? '' : env.CHANGE_ID}"
SONAR_TOKEN = credentials('android-sonarcloud-token')
}
steps {
script {
echo 'Running sonarqube'
sh 'echo $BITRISE_GIT_BRANCH'
sh 'echo $BITRISEIO_GIT_BRANCH_DEST'
sh 'echo $BITRISE_PULL_REQUEST'
sh './gradlew sonarqube'
}
}
}
stage('Build Test APKs') {
steps {
script {
echo 'Building UI APKs'
sh './gradlew :app:assembleDhisUITestingDebug :app:assembleDhisUITestingDebugAndroidTest :compose-table:assembleAndroidTest'
}
}
}
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}"
}
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}"
}
steps {
dir("${env.WORKSPACE}/scripts"){
script {
echo 'Browserstack deployment and running tests'
sh 'chmod +x browserstackJenkins.sh'
sh './browserstackJenkins.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
}