我是Jenkins job-dsl脚本的新手。
我正在尝试使用插件(https://github.com/AOEpeople/gradle-jenkins-job-dsl-plugin)将Jenkins XML配置转换为Groovy DSL脚本,该插件使用Gradle工具构建脚本并在本地运行单元测试。
但是,目前,我正面临来自第三方Jenkins插件(https://github.com/jenkinsci/ghprb-plugin)的扩展DSL的问题。
triggers {
githubPullRequest {
orgWhitelist("Test")
cron("H/5 * * * *")
extensions {
commitStatus {
completedStatus('SUCCESS', 'Build succeeded.')
completedStatus('FAILURE', 'Build failed.')
}
}
}
}
由于以下问题,Gradle无法生成脚本:
Expected no exception to be thrown, but got 'javaposse.jobdsl.dsl.DslScriptException'
at spock.lang.Specification.noExceptionThrown(Specification.java:119)
at com.aoe.gradle.jenkinsjobdsl.JobScriptsSpec.test DSL script #file.name(JobScriptsSpec.groovy:55)
Caused by: javaposse.jobdsl.dsl.DslScriptException: (PullRequestJobTemplate.groovy, line 59) No signature of method: static org.apache.commons.lang.ClassUtils.isAssignable() is applicable for argument types: ([Ljava.lang.Class;, [Ljava.lang.Class;, java.lang.Boolean) values: [[class com.unified.dsl.templates.PullRequestJobTemplate$_closure1$_closure5$_closure15], ...]
Possible solutions: isAssignable([Ljava.lang.Class;, [Ljava.lang.Class;), isAssignable(java.lang.Class, java.lang.Class)
at javaposse.jobdsl.dsl.AbstractDslScriptLoader.runScriptEngine(AbstractDslScriptLoader.groovy:107)
at javaposse.jobdsl.dsl.AbstractDslScriptLoader.runScripts_closure1(AbstractDslScriptLoader.groovy:60)
at groovy.lang.Closure.call(Closure.java:414)
at groovy.lang.Closure.call(Closure.java:430)
at javaposse.jobdsl.dsl.AbstractDslScriptLoader.runScripts(AbstractDslScriptLoader.groovy:46)
at javaposse.jobdsl.dsl.AbstractDslScriptLoader.runScript(AbstractDslScriptLoader.groovy:81)
at com.aoe.gradle.jenkinsjobdsl.JobScriptsSpec.test DSL script #file.name(JobScriptsSpec.groovy:51)
Caused by: groovy.lang.MissingMethodException: No signature of method: static org.apache.commons.lang.ClassUtils.isAssignable() is applicable for argument types: ([Ljava.lang.Class;, [Ljava.lang.Class;, java.lang.Boolean) values: [[class com.unified.dsl.templates.PullRequestJobTemplate$_closure1$_closure5$_closure15], ...]
Possible solutions: isAssignable([Ljava.lang.Class;, [Ljava.lang.Class;), isAssignable(java.lang.Class, java.lang.Class)
at javaposse.jobdsl.plugin.ExtensionPointHelper.findExtensionPoints_closure1(ExtensionPointHelper.groovy:24)
at javaposse.jobdsl.plugin.ExtensionPointHelper.findExtensionPoints(ExtensionPointHelper.groovy:23)
at javaposse.jobdsl.plugin.JenkinsJobManagement.callExtension(JenkinsJobManagement.java:365)
at javaposse.jobdsl.dsl.AbstractExtensibleContext.methodMissing(AbstractExtensibleContext.groovy:17)
at com.unified.dsl.templates.PullRequestJobTemplate.closure1$_closure5(PullRequestJobTemplate.groovy:59)
at com.unified.dsl.templates.PullRequestJobTemplate.closure1$_closure5(PullRequestJobTemplate.groovy)
at javaposse.jobdsl.dsl.ContextHelper.executeInContext(ContextHelper.groovy:16)
at javaposse.jobdsl.dsl.Job.triggers(Job.groovy:568)
at com.unified.dsl.templates.PullRequestJobTemplate$_closure1.doCall(PullRequestJobTemplate.groovy:58)
at groovy.lang.Closure.call(Closure.java:414)
at groovy.lang.Closure.call(Closure.java:430)
at groovy.lang.Closure.call(Closure.java:430)
at javaposse.jobdsl.dsl.JobParent.processItem(JobParent.groovy:114)
at javaposse.jobdsl.dsl.JobParent.freeStyleJob(JobParent.groovy:47)
at com.unified.dsl.base.JobBuilder.build(JobBuilder.groovy:52)
at stage.script.run(script:12)
at javaposse.jobdsl.dsl.AbstractDslScriptLoader.runScript(AbstractDslScriptLoader.groovy:124)
at javaposse.jobdsl.dsl.AbstractDslScriptLoader.runScriptEngine(AbstractDslScriptLoader.groovy:101)
... 6 more
答案 0 :(得分:0)
因此,您正在获取的堆栈跟踪是由Spock Test生成的,它会检查job-dsl脚本是否编译。所以你已经正确设置了你的开发环境!总是一个好的开始。
现在您需要做的就是设置本地Jenkins运行时,以便在Spock Test启动时生成Jenkins XML配置文件。
回顾你的job-dsl脚本我必须说它对我来说很好看。具体来说,我将它与GitHub拉请求构建器插件的主页上的完整示例job-dsl进行了比较......
堆栈跟踪的关键部分是这一行
PullRequestJobTemplate.groovy, line 59) No signature of method:
static org.apache.commons.lang.ClassUtils.isAssignable() is applicable
for argument types: ([Ljava.lang.Class;, [Ljava.lang.Class;,
java.lang.Boolean) values: [[class com.unified.dsl.templates.PullRequestJobTemplate$_closure1$_closure5$_closure15], ...]
对我来说,这表明仍然缺少运行时依赖性,以允许GH PR Builder插件job-dsl按预期运行。
进一步检查插件页面我注意到以下依赖项是不同的必需和可选的......
credentials (version:1.21)
matrix-project (version:1.6)
build-flow-plugin (version:0.12, optional)
ssh-agent (version:1.3)
structs (version:1.6)
github (version:1.26.0)
git (version:2.4.0)
github-api (version:1.82)
plain-credentials (version:1.1)
job-dsl (version:1.39, optional)
token-macro (version:1.10, optional)
如果将这些添加到Gradle构建中,那么我会说将生成您的XML。
完成job-dsl开发后,不要忘记将这些依赖项添加到目标Jenkins服务器。