Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Emulator For Jenkins Pipeline

Looking for a Jenkins plug-in that will emulate Android in a pipeline job.

This plug-in works well in a Freestyle job but doesn't support pipelines at this point in time.

Is there any alternative for running functional tests on Android via a Jenkins pipeline?

like image 566
brendan.markham Avatar asked Sep 19 '16 06:09

brendan.markham


Video Answer


2 Answers

This is my solution. Hope it helps.

node {
  try{
    def ANDROID_HOME='/opt/android-sdk-linux'
    def ADB="$ANDROID_HOME/platform-tools/adb"

    stage('Stage Checkout') {
      git branch: 'develop', credentialsId: 'd9f13c8b-f917-4374-8849-2b9730885333', url: 'http://git.hostname.com/something.git'
    }

    stage('Stage Build') {
      sh "./gradlew clean assembleRelease"
    }

    stage('Stage Unit Tests') {
      sh "./gradlew testReleaseUnitTest"
    }

    stage('Stage Instumental Tests') {
      sh "$ADB start-server"

      def error
      parallel (
        launchEmulator: {
            sh "$ANDROID_HOME/tools/qemu/linux-x86_64/qemu-system-x86_64 -engine classic -prop persist.sys.language=en -prop persist.sys.country=US -avd test -no-snapshot-load -no-snapshot-save -no-window"
        },
        runAndroidTests: {
            timeout(time: 20, unit: 'SECONDS') {
              sh "$ADB wait-for-device"
            }
            try {
                sh "./gradlew :MyKet:connectedAndroidTest"
            } catch(e) {
                error = e
            }
            sh script: '/var/lib/jenkins/kill-emu.sh'
        }
      )
      if (error != null) {
          throw error
      }
    }
    currentBuild.result = "SUCCESS"
  } catch (e) {
    currentBuild.result = "FAILED"
//    notifyFailed()
    throw e
  } finally {
    stage('Stage Clean') {
       sh script: '/var/lib/jenkins/clean.sh'
    }
  }
}
like image 119
hadilq Avatar answered Sep 20 '22 15:09

hadilq


You can run an emulator with this shell script:

sh '${ANDROID_HOME}/emulator -avd <avd_name> [<options>]'

Before that you should create an avd once:

~/.android/android create avd ...

or use the UI for it.

You can find more information here

Also here is a suggestion for the Jenkins issue:

step([
        $class: 'AndroidEmulator',
        osVersion: 'android-23',
        screenResolution: '1080x1920',
        screenDensity: 'xxhdpi',
        deviceLocale: 'en_US',
        targetAbi: 'x86',
        sdCardSize: '200M',
        showWindow: true,
        commandLineOptions: '-noaudio -gpu mesa -qemu -m 1024 -enable-kvm'
])

Did you try it?

like image 23
Pazonec Avatar answered Sep 20 '22 15:09

Pazonec