Skip to content

Instantly share code, notes, and snippets.

@mlabouardy
Last active April 15, 2019 20:45
Show Gist options
  • Select an option

  • Save mlabouardy/be108964530a0ffe1498e004c93c6aa2 to your computer and use it in GitHub Desktop.

Select an option

Save mlabouardy/be108964530a0ffe1498e004c93c6aa2 to your computer and use it in GitHub Desktop.
CI/CD for Android app on Jenkins
def bucket = 'mobile-artifacts-foxintelligence'
node('android') {
try {
stage('Checkout') {
checkout scm
notifySlack('STARTED')
}
stage('Clean & Prepare') {
sh "./gradlew clean"
}
stage('Quality Tests') {
sh "./gradlew lintDebug"
androidLint pattern: 'app/build/reports/lint-results-debug.xml'
}
stage('Unit Tests') {
sh "./gradlew testDebug --stacktrace"
if (env.BRANCH_NAME == 'master'){
sh "./gradlew testReleaseUnitTest"
}
if (env.BRANCH_NAME == 'preprod'){
sh "./gradlew testStagingUnitTest"
}
if (env.BRANCH_NAME == 'develop'){
sh "./gradlew testSandboxUnitTest"
}
publishHTML([reportDir: 'app/build/reports/tests/testDebugUnitTest', reportFiles: 'index.html', reportName: 'Unit Tests Report'])
junit 'app/build/test-results/testDebugUnitTest/*.xml'
}
stage('Build'){
sh "./gradlew assembleDebug"
if (env.BRANCH_NAME == 'master'){
sh "./gradlew compileReleaseKotlin"
}
if (env.BRANCH_NAME == 'preprod'){
sh "./gradlew compileStagingKotlin"
}
if (env.BRANCH_NAME == 'develop'){
sh "./gradlew compileSandboxKotlin"
}
}
stage('Push'){
sh "aws s3 cp app/build/outputs/apk/debug/app-debug.apk s3://${bucket}/android/${commitID()}.apk"
}
stage('UI Tests'){
sh "./gradlew assembleDebugAndroidTest"
sh "gcloud firebase test android run --app app/build/outputs/apk/debug/app-debug.apk --test app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk"
}
}catch(e){
currentBuild.result = 'FAILED'
throw e
}finally{
notifySlack(currentBuild.result)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment