【问题标题】:jenkins uiautomator build always greenjenkins uiautomator 构建始终绿色
【发布时间】:2013-08-07 19:26:21
【问题描述】:

所以我定义了很多 UiAutomatorTestCase 类,每个类最多有 1 或 2 个测试用例。 然后我在 Jenkins 上使用 Shell 脚本将这些测试用例串成一系列测试,例如:

adb shell uiautomator runtest myTest.jar -c com.myTest.TestClass1
adb shell uiautomator runtest myTest.jar -c com.myTest.TestClass2
adb shell uiautomator runtest myTest.jar -c com.myTest.TestClass3
adb shell uiautomator runtest myTest.jar -c com.myTest.TestClass4
...
so on so forth.

我遇到的两个 (1/2) 问题之一是,对于 Jenkins 构建,这些测试中的任何一个是否失败都没有关系,Jenkins 总是显示为绿色,我需要 Jenkins 停止并显示红色的构建.

另一个 (2/2) 问题是,如果应用程序在其中一个测试(例如 TestClass2)中崩溃,脚本将尝试获取并继续执行。使脚本停止的最佳方法是什么?

有什么建议吗? 谢谢

【问题讨论】:

    标签: android jenkins android-uiautomator


    【解决方案1】:

    感谢@KeepCalmAndCarryOn 和 Daniel Beck,我通过 2 个步骤解决了我的问题:

    1. 记录 adb 输出
    2. grep 日志中的关键字

    shell 脚本中的代码是:

    #!bin/bash
    
    function punch() {
      "$@" | tee ${WORKSPACE}/adb_output.log
      [[ -z "$(grep 'FAILURES!!!' ${WORKSPACE}/adb_output.log)" ]] || exit 1
    }
    
    punch adb shell uiautomator runtest myTest.jar -c com.myTest.TestClass1
    punch adb shell uiautomator runtest myTest.jar -c com.myTest.TestClass2
    ...
    

    【讨论】:

      【解决方案2】:

      您需要检查您正在运行的每条 adb 语句的退出代码,然后再进行下一条

      此处的这篇文章详细介绍了使用 bash Checking Bash exit status of several commands efficiently 检查退出代码

      包括这个(为你的例子而改变)

      function test {
          "$@"
          status=$?
          if [ $status -ne 0 ]; then
              echo "error with $1"
              exit "$status"
          fi
          return $status
      }
      
      test adb shell uiautomator runtest myTest.jar -c com.myTest.TestClass1
      test adb shell uiautomator runtest myTest.jar -c com.myTest.TestClass2
      

      您还可以通过在脚本的第一行添加 shebang 来告诉 Jenkins 使用 bash

      #!/bin/bash
      

      【讨论】:

      • @KeepCalAndCarryOn 感谢您的回复,但我失败了!!!测试运行:1,失败:0,错误:1 INSTRUMENTATION_STATUS_CODE:-1 + s=0 + '[' 0 -ne 0 ']' + return 0 我在 if 子句中也取出了出口“$status” .也许在这种情况下 $1 是单独的 adb (这解释了返回 0)?
      猜你喜欢
      • 2014-07-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-10
      • 2015-10-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多