8

嗨,我已经在 J​​enkins 上建立了我的 Android 项目来提供 CI。它运行良好,在连接的 Android 手机上运行测试。测试在扩展 jUnit3 的 Android 测试框架上运行。

不幸的是,如果有任何测试失败,构建将被标记为失败。我希望能够通过两种方式改进这一点:

  1. 允许不稳定的构建
  2. 能够标记已知的测试失败

对于第 1 项,我尝试将其添加到项目 build.gradle 中:

connectedCheck {
    ignoreFailures = true
}

但它没有效果。查看构建日志,我意识到实际的测试任务叫做connectedInstrumentTest,但是没有找到这个任务:

connectedInstrumentTest {
    ignoreFailures = true
}

原因:

在项目“:Playtime”上找不到参数 [build_4ldpah0qgf0ukktofecsq41r98$_run_closure3@9cd826] 的方法 connectedInstrumentTest()。

那是我失踪了吗?

谢谢

编辑:继承我的项目 build.gradle,没什么特别的:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.5.+'
    }
}
apply plugin: 'android'

dependencies {
    compile files('libs/android-support-v4.jar')
}

android {
    compileSdkVersion 17
    buildToolsVersion "18.0.1"

    defaultConfig {
        minSdkVersion 8
        targetSdkVersion 16
        testPackageName "com.bb.pt.test"
        testInstrumentationRunner "android.test.InstrumentationTestRunner"
    }
}

connectedCheck {
    ignoreFailures = true
}

我在詹金斯的 gradle 设置:

switches: --stacktrace --info
tasks: :pt:assembleDebug :pt:assembleTest :pt:connectedCheck

编辑:

我建立了 gradlew 并尝试了。相同的输出。如果测试失败,我不希望构建失败:

:pt:connectedInstrumentTest FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':pt:connectedInstrumentTest'.
> There were failing tests. See the report at: file:///home/simon/WorkingCopies/bb/code/trunk/pt/pt/build/reports/instrumentTests/connected/index.html

* Try:
Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output.

BUILD FAILED

我试图在 build.gradle 中限定任务名称:

task connectedCheck {
    ignoreFailures = true
}

但它认为我正在尝试添加新任务而不是修改现有任务。

FAILURE: Build failed with an exception.

* Where:
Build file '/home/simon/WorkingCopies/bb/code/trunk/pt/pt/build.gradle' line: 31

* What went wrong:
A problem occurred evaluating project ':pt'.
> Cannot add task ':pt:connectedCheck' as a task with that name already exists.
4

1 回答 1

11

经过我们的交谈,我相信:

  • 问题仅与 gradle 配置有关,与 jenkins 无关。让它在 gradle 中工作。
  • 在gradle中我相信(虽然我不是专家)你应该让connectedInstrumentTest忽略失败,但你尝试使用以下失败

    connectedInstrumentTest {
        ignoreFailures = true
    }
    
  • 也许解决方案是像这样包装这个配置节点:

    project.gradle.taskGraph.whenReady {
      connectedInstrumentTest {
        ignoreFailures = true
      }
    }
    

https://github.com/stanfy/hotandroid/blob/master/part0/build.gradle

于 2013-08-21T05:47:30.347 回答