我一直在尝试使用Jenkins从build.gradle文件中运行单元测试。如果我在android studio的终端中使用命令./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包装器调用我的Jenkins设置并调用等级选项(使用jenkins的等级插件)并且都不起作用。
答案 0 :(得分:3)
问题是来自Jenkins服务器的路径不正确。在我重命名一个工作后,我没有意识到创建了一个全新的工作区,所以我指向了以前的工作区。另外我发现最好使用shell命令而不是Jenkins的等级插件,因为这是我能够追踪我的问题的方法。