【发布时间】:2016-07-29 20:35:06
【问题描述】:
我正在使用 Jenkins 作为构建步骤运行 gradlew。 build.gradle 中有一个测试任务。当测试任务运行时,它会失败,因为它试图编译的 Groovy 文件顶部有 5 个 import 语句。这些类是我在子文件夹中创建的。但是,当我使用 Job DSL 插件使用相同的 Groovy 文件创建 Jenkins Jobs 时,它运行得很好。以下是我看到的错误:
09:32:31.930 [DEBUG] [TestEventLogger] debug.JobScriptsSpec > test script JenkinsJobs.groovy FAILED
09:32:31.930 [DEBUG] [TestEventLogger] Expected no exception to be thrown, but got 'javaposse.jobdsl.dsl.DslException'
09:32:31.930 [DEBUG] [TestEventLogger] at spock.lang.Specification.noExceptionThrown(Specification.java:118)
09:32:31.930 [DEBUG] [TestEventLogger] at debug.JobScriptsSpec.test script #file.name(JobScriptsSpec.groovy:31)
09:32:31.930 [DEBUG] [TestEventLogger]
09:32:31.930 [DEBUG] [TestEventLogger] Caused by:
09:32:31.930 [DEBUG] [TestEventLogger] javaposse.jobdsl.dsl.DslException: startup failed:
09:32:31.945 [DEBUG] [TestEventLogger] script: 1: unable to resolve class utilities.GitConfiguration
09:32:31.945 [DEBUG] [TestEventLogger] @ line 1, column 1.
09:32:31.945 [DEBUG] [TestEventLogger] import utilities.GitConfiguration
09:32:31.945 [DEBUG] [TestEventLogger]
我正在模仿这里正在做的事情:https://github.com/sheehan/job-dsl-gradle-example 请注意“测试”部分。
我已经尝试添加到类路径中,但我仍然遇到同样的错误:
buildscript {
dependencies {
classpath files('/jobs/utilities')
}
}
我的基本文件结构是这样的:
jenkins-jobs
|-build.gradle
|-jobs
|-JenkinsJobs.groovy
|-utilities
|-GitConfiguration.groovy
|-other groovy files I try to import
简而言之,我想问的问题是,在尝试将用户创建的导入包含在我的 Groovy 文件中时,如何让 Gradle 满意?
【问题讨论】:
标签: java jenkins gradle groovy jenkins-job-dsl