【问题标题】:Android Emulator For Jenkins PipelineJenkins 流水线的 Android 模拟器
【发布时间】:2016-09-19 06:18:16
【问题描述】:

正在寻找一个在管道作业中模拟 Android 的 Jenkins 插件。

This plug-in 在 Freestyle 工作中表现良好,但此时 doesn't support pipelines

有没有其他方法可以通过 Jenkins 管道在 Android 上运行功能测试?

【问题讨论】:

    标签: android jenkins android-emulator jenkins-pipeline


    【解决方案1】:

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

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

    【讨论】:

    • 请提供你的shell脚本,没有它们这个答案是不完整的
    【解决方案2】:

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

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

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

    ~/.android/android create avd ...
    

    或使用 UI。

    您可以找到更多信息here

    这里还有一个关于 Jenkins 问题的建议:

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

    你试过了吗?

    【讨论】:

    • 呵呵,没想到直接用sh调用模拟器。现在应该可以了。希望现在有一种可用于管道的工具模式。
    • Jenkins 问题中的step 示例是一种用于实例化类的建议方法;这实际上还没有实现。
    • Jenkins Android Emulator 插件目前与 Pipeline 不兼容。
    猜你喜欢
    • 2021-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-29
    • 1970-01-01
    • 2022-09-26
    • 2017-12-07
    相关资源
    最近更新 更多