2

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

我的 build.gradle 中的代码片段

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

詹金斯输出

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 包装器和调用等级选项(使用等级插件詹金斯),两者都不起作用。

4

1 回答 1

3

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

于 2015-09-15T10:41:12.510 回答