How to import and run 3rd party Jenkins Plugin's extension DSL (githubPullRequest) with Gradle tool locally?

允我心安 提交于 2021-01-01 03:35:33

问题


I'm a newbie at Jenkins job-dsl scripting.

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.

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.')
             }
         }
     }
}

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

回答1:


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.

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.

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 ...

https://wiki.jenkins.io/display/JENKINS/GitHub+pull+request+builder+plugin#GitHubpullrequestbuilderplugin-JobDSLSupport

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], ...]

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)

If you add these to the Gradle build then I would say that your XML will be generated.

Don't forget to add these dependencies to the target Jenkins server when you have completed your job-dsl development.



来源:https://stackoverflow.com/questions/46899830/how-to-import-and-run-3rd-party-jenkins-plugins-extension-dsl-githubpullreques

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!