问题描述
我是Jenkins job-dsl脚本的新手.
I'm a newbie at Jenkins job-dsl scripting.
我正在使用插件将Jenkins XML配置转换为Groovy DSL脚本( https://github.com/AOEpeople/gradle-jenkins-job-dsl-plugin ),该文件使用Gradle工具构建脚本并在本地运行单元测试.
I'm working to convert the Jenkins XML configuration to Groovy DSL script using a plugin (https://github.com/AOEpeople/gradle-jenkins-job-dsl-plugin) that uses Gradle tool for building the script and running Unit Test locally.
但是,目前,我遇到了来自第三方Jenkins插件的扩展DSL问题( https://github.com/jenkinsci/ghprb-plugin ).
However, currently, I'm facing an issue with the extension DSL from a 3rd Party Jenkins Plugin (https://github.com/jenkinsci/ghprb-plugin).
triggers {
githubPullRequest {
orgWhitelist("Test")
cron("H/5 * * * *")
extensions {
commitStatus {
completedStatus('SUCCESS', 'Build succeeded.')
completedStatus('FAILURE', 'Build failed.')
}
}
}
}
由于以下原因,Gradle无法生成脚本:
The script cannot be generated by Gradle because of the issue:
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
推荐答案
因此Spock测试正在生成您正在获取的堆栈跟踪,该检查检查一下job-dsl脚本是否可以编译.因此,您已经正确设置了开发环境!总是一个好的开始.
So the stacktrace you are getting is being generated by the Spock Test that checks to see if the job-dsl script compiles. So you have set up your development environment correctly! Always a good start.
现在您需要做的就是设置本地Jenkins运行时,以允许在Spock测试启动时生成Jenkins XML配置文件.
Now all you need to do is setup your local Jenkins runtime to allow the Jenkins XML config file to be generated when it is kicked off by the Spock Test.
查看您的job-dsl脚本,我必须说它对我来说看起来不错.具体来说,我将它与GitHub pull request builder插件主页上的完整示例job-dsl进行了比较...
Reviewing your job-dsl script I must say it looks good to me. Specifically I compared it to the complete sample job-dsl on the GitHub pull request builder plugin's home page ...
堆栈跟踪的关键部分是此行
The key part of the stack trace is this line here
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能够按预期运行.
To me this would indicate that there was still a run-time dependency missing to allow the GH PR Builder plugin job-dsl to run as expected.
进一步查看插件页面时,我注意到以下依赖项是各种必需的和可选的...
Further reviewing the plugin page I note that the following dependencies are variously required and optional ...
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.
If you add these to the Gradle build then I would say that your XML will be generated.
在完成job-dsl开发后,请不要忘记将这些依赖项添加到目标Jenkins服务器.
Don't forget to add these dependencies to the target Jenkins server when you have completed your job-dsl development.
这篇关于如何使用Gradle工具在本地导入和运行第三方Jenkins插件的扩展DSL(githubPullRequest)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!