如何在本地导入和运行第三方 Jenkins 插件的扩展 DSL (githubPullRequest) 与 Gradle 工具?



我是Jenkins job dsl脚本的新手。

我正在使用插件将Jenkins XML配置转换为GroovySSL脚本(https://github.com/AOEpeople/gradle-jenkins-job-dsl-plugin)它使用Gradle工具构建脚本并在本地运行单元测试。

然而,目前,我正面临来自第三方Jenkins插件的DSL扩展问题(https://github.com/jenkinsci/ghprb-plugin)。

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

因此,您获得的堆栈跟踪是由斯波克测试生成的,该测试检查作业dsl脚本是否编译。所以您已经正确地设置了开发环境!总是一个好的开始。

现在,您所需要做的就是设置本地Jenkins运行时,以便在Spock测试启动时生成Jenkins XML配置文件。

回顾你的作业dsl脚本,我必须说它对我来说很好。特别是,我将它与GitHub pull request builder插件主页上的完整示例作业dsl进行了比较。。。

https://wiki.jenkins.io/display/JENKINS/GitHub+pull+request+builder+plugin#GitHubpullrequestbuilderplugin JobDSL支持

堆栈跟踪的关键部分是

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插件作业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将被生成。

在完成工作dsl开发后,不要忘记将这些依赖项添加到目标Jenkins服务器中。

相关内容

  • 没有找到相关文章

最新更新