Jenkins Pipeline的Android模拟器

时间:2016-09-19 06:18:17

标签: android jenkins android-emulator jenkins-pipeline

寻找能够在管道作业中模拟Android的Jenkins插件。

This plug-in在自由式作业中表现良好,但此时此作为doesn't support pipelines

是否可以通过Jenkins管道在Android上运行功能测试?

2 个答案:

答案 0 :(得分:3)

这是我的解决方案。希望它有所帮助。

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'
    }
  }
}

答案 1 :(得分:1)

您可以使用此shell脚本运行模拟器:

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

在此之前,你应该创建一次avd

~/.android/android create avd ...

或使用UI。

您可以找到更多信息here

此处还有关于詹金斯问题的建议:

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'
])

你试过吗?