在Jenkins上允许不稳定的Android Gradle构建

时间:2013-08-18 12:32:05

标签: android jenkins gradle android-testing build.gradle

您好我已经在Jenkins上设置我的Android项目来提供CI。它运行良好,在连接的Android手机上运行测试。测试在Android测试框架上运行,扩展了jUnit3。

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

  1. 允许不稳定的构建
  2. 能够标记已知的测试失败
  3. 对于第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.
    

1 个答案:

答案 0 :(得分:11)

在我们的谈话之后,我相信:

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

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

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

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

相关问题