android - Jenkins 无法识别自定义 Gradle 任务

标签 android android-studio jenkins build.gradle gradle-plugin

我一直在尝试使用 Jenkins 从我的 build.gradle 文件运行单元测试。如果我在 android studio 的终端中使用命令./gradlewtask,我就可以看到我设置的自定义任务。但是,如果我尝试通过 jenkins 运行相同的命令,我将无法在任务输出中看到它们。

我的 build.gradle 中的代码 fragment

task runDataUnitTests(dependsOn: [':data:test']) {
    description 'Run unit tests for data layer.'
}

task runBusinessUnitTests(dependsOn: [':business:test']) {
    description 'Run unit tests for business layer.'
}

task runPresenterUnitTests(dependsOn: [':presenter:test']) {
    description 'Run unit tests for presenter layer.'
}

task runAllUnitTests(dependsOn: [runDataUnitTests, runBusinessUnitTests, runPresenterUnitTests]) << {
    group = 'My tasks'
    description 'Run unit tests for all layers.'
}

task testingTaskmma{
    group = 'My tasks'
    println 'is this task seen'
}

Android Studio 输出

Other tasks
-----------
assembleArtifacts - Builds the project artifacts
assembleDefault
crashlyticsUploadDistributionLiveDebug - Uploads an APK to Crashlytics for distribution.
crashlyticsUploadDistributionLiveRelease - Uploads an APK to Crashlytics for distribution.
crashlyticsUploadDistributionStagingDebug - Uploads an APK to Crashlytics for distribution.
crashlyticsUploadDistributionStagingRelease - Uploads an APK to Crashlytics for distribution.
hello
jarLiveDebugClasses
jarLiveReleaseClasses
jarStagingDebugClasses
jarStagingReleaseClasses
lintVitalLiveRelease - Runs lint on just the fatal issues in the LiveRelease build.
lintVitalStagingRelease - Runs lint on just the fatal issues in the StagingRelease build.
runAllUnitTests **<<< THIS DUDE HERE**
sonarqube - Analyzes project ':msmandroidapp' and its subprojects with SonarQube.
sonarRunner - Analyzes project ':msmandroidapp' and its subprojects with Sonar Runner.
testingTaskmsma

Jenkins 输出

Other tasks
-----------
assembleArtifacts - Builds the project artifacts
assembleDefault
connectedInstrumentTest - Installs and runs instrumentation tests for all flavors on connected devices.
connectedLiveTest - Installs and runs the tests for LiveDebug flavor on connected devices.
connectedStagingTest - Installs and runs the tests for StagingDebug flavor on connected devices.
crashlyticsUploadDistributionLiveDebug - Uploads an APK to Crashlytics for distribution.
crashlyticsUploadDistributionLiveDebugAndroidTest - Uploads an APK to Crashlytics for distribution.
crashlyticsUploadDistributionLiveRelease - Uploads an APK to Crashlytics for distribution.
crashlyticsUploadDistributionStagingDebug - Uploads an APK to Crashlytics for distribution.
crashlyticsUploadDistributionStagingDebugAndroidTest - Uploads an APK to Crashlytics for distribution.
crashlyticsUploadDistributionStagingRelease - Uploads an APK to Crashlytics for distribution.
jarLiveDebugClasses
jarLiveReleaseClasses
jarStagingDebugClasses
jarStagingReleaseClasses
publishLive - Uploads a live-flavor specific APK to MobileAppStore
publishStaging - Uploads a staging-flavor specific APK to MobileAppStore
sonarRunner - Analyzes project ':msmandroidapp' and its subprojects with Sonar Runner.
uploadArtifacts - Builds the project artifacts and uploads them the to local maven repository.

正如您所看到的,我创建的其他自定义任务也从 jenkins 输出中丢失(例如,testingTaskmsma、hello 等) 我已经尝试使用 gradle 包装器和调用等级选项(使用 jenkins 的等级插件)来设置 Jenkins,但都不起作用。

最佳答案

问题是 Jenkins 服务器的路径不正确。重命名作业后,我没有意识到创建了一个全新的工作区,因此我指向以前的工作区。我还发现最好使用 shell 命令而不是 Jenkins 的 Grade 插件,因为这就是我能够追踪问题的方式。

关于android - Jenkins 无法识别自定义 Gradle 任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32567810/

相关文章:

android - 当您有一个包含 2 个 fragment 的 Activity 时,将 fragment 添加到 addToBackstack

android 多点触控图像缩放?

Android检测按下电源键

android - 层保存标志无效 - Android 9 仅允许使用 ALL_SAVE_FLAGS

java - 如何在 Jenkins 上设置 LD_LIBRARY_PATH

java - 通过 Retrofit 为 FragmentPagerAdapter 中的 Fragment 获取不同的数据,用于几个 tablayout 选项卡

android - Android Studio 布局编辑器中缺少属性

android - 如何在android studio中打开android文档和代码示例

docker - 如何解决 gradle 在 docker 环境中被破坏的问题?

linux - 在没有 GUI 的 Linux 机器上通过 jenkins 执行 Selenium 测试(仅限 CLI)- HEADLESS 模式