Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Is it possible to configure this plugin on GitHub Organization using Job DSL? #95

Open
thorntonryan opened this issue Dec 9, 2020 · 4 comments

Comments

@thorntonryan
Copy link

Hello,

According to the doc it looks like this plugin should be compatible with a GitHub Organization Folder ... somehow.

The Job DSL API viewer installed on my Jenkins instance dynamically detected the issueCommentTrigger and seems to think I can configure the plugin by adding it to my org underneath the triggers section:

organizationFolder("foo") {
    triggers {
        issueCommentTrigger {
            commentPattern('.*Do: Test.*')
        }
    }
}

But if I run my Job DSL I get the following errors:

Processing provided DSL script
java.lang.ClassCastException: class jenkins.branch.OrganizationFolder cannot be cast to class org.jenkinsci.plugins.workflow.job.WorkflowJob (jenkins.branch.OrganizationFolder is in unnamed module of loader hudson.ClassicPluginStrategy$AntClassLoader2 @6e966dfc; org.jenkinsci.plugins.workflow.job.WorkflowJob is in unnamed module of loader hudson.ClassicPluginStrategy$AntClassLoader2 @62c3180d)
	at org.jenkinsci.plugins.pipeline.github.trigger.IssueCommentTrigger.start(IssueCommentTrigger.java:34)
	at com.cloudbees.hudson.plugins.folder.computed.ComputedFolder.init(ComputedFolder.java:199)
	at com.cloudbees.hudson.plugins.folder.AbstractFolder.onLoad(AbstractFolder.java:544)
	at com.cloudbees.hudson.plugins.folder.computed.ComputedFolder.onLoad(ComputedFolder.java:221)
	at jenkins.branch.OrganizationFolder.onLoad(OrganizationFolder.java:230)
	at hudson.model.Items.load(Items.java:380)
	at hudson.model.ItemGroupMixIn$4.call(ItemGroupMixIn.java:281)
	at hudson.model.ItemGroupMixIn$4.call(ItemGroupMixIn.java:279)
	at hudson.model.Items.whileUpdatingByXml(Items.java:136)
	at hudson.model.ItemGroupMixIn.createProjectFromXML(ItemGroupMixIn.java:279)
	at com.cloudbees.hudson.plugins.folder.Folder.createProjectFromXML(Folder.java:255)
	at javaposse.jobdsl.plugin.JenkinsJobManagement.createNewItem(JenkinsJobManagement.java:517)
	at javaposse.jobdsl.plugin.JenkinsJobManagement.createOrUpdateConfig(JenkinsJobManagement.java:141)
	at javaposse.jobdsl.dsl.JobManagement$createOrUpdateConfig$2.call(Unknown Source)
	at javaposse.jobdsl.plugin.InterruptibleJobManagement.createOrUpdateConfig(InterruptibleJobManagement.groovy:35)
	at javaposse.jobdsl.dsl.JobManagement$createOrUpdateConfig$2.call(Unknown Source)
	at javaposse.jobdsl.dsl.AbstractDslScriptLoader$_extractGeneratedJobs_closure4.doCall(AbstractDslScriptLoader.groovy:204)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
	at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
	at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:294)
	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
	at groovy.lang.Closure.call(Closure.java:414)
	at groovy.lang.Closure.call(Closure.java:430)
	at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:2040)
	at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:2025)
	at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:2066)
	at org.codehaus.groovy.runtime.dgm$163.invoke(Unknown Source)
	at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoMetaMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:274)
	at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:56)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
	at javaposse.jobdsl.dsl.AbstractDslScriptLoader.extractGeneratedJobs(AbstractDslScriptLoader.groovy:197)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:210)
	at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:59)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:174)
	at javaposse.jobdsl.dsl.AbstractDslScriptLoader.extractGeneratedItems(AbstractDslScriptLoader.groovy:184)
	at javaposse.jobdsl.plugin.JenkinsDslScriptLoader.extractGeneratedItems(JenkinsDslScriptLoader.java:22)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
	at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
	at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:384)
	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
	at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:69)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:182)
	at javaposse.jobdsl.dsl.AbstractDslScriptLoader$_runScripts_closure1.doCall(AbstractDslScriptLoader.groovy:63)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
	at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
	at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:294)
	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
	at groovy.lang.Closure.call(Closure.java:414)
	at groovy.lang.Closure.call(Closure.java:430)
	at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:2040)
	at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:2025)
	at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:2066)
	at org.codehaus.groovy.runtime.dgm$163.invoke(Unknown Source)
	at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoMetaMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:274)
	at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:56)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
	at javaposse.jobdsl.dsl.AbstractDslScriptLoader.runScripts(AbstractDslScriptLoader.groovy:46)
	at javaposse.jobdsl.plugin.SecureDslScriptLoader.super$2$runScripts(SecureDslScriptLoader.groovy)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
	at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1213)
	at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuperN(ScriptBytecodeAdapter.java:132)
	at javaposse.jobdsl.plugin.SecureDslScriptLoader.runScripts(SecureDslScriptLoader.groovy:14)
	at javaposse.jobdsl.plugin.ExecuteDslScripts.perform(ExecuteDslScripts.java:351)
	at jenkins.tasks.SimpleBuildStep.perform(SimpleBuildStep.java:123)
	at hudson.tasks.BuildStepCompatibilityLayer.perform(BuildStepCompatibilityLayer.java:80)
	at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
	at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:803)
	at hudson.model.Build$BuildExecution.build(Build.java:197)
	at hudson.model.Build$BuildExecution.doRun(Build.java:163)
	at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:513)
	at hudson.model.Run.execute(Run.java:1907)
	at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
	at hudson.model.ResourceController.execute(ResourceController.java:97)
	at hudson.model.Executor.run(Executor.java:429)
ERROR: class jenkins.branch.OrganizationFolder cannot be cast to class org.jenkinsci.plugins.workflow.job.WorkflowJob (jenkins.branch.OrganizationFolder is in unnamed module of loader hudson.ClassicPluginStrategy$AntClassLoader2 @6e966dfc; org.jenkinsci.plugins.workflow.job.WorkflowJob is in unnamed module of loader hudson.ClassicPluginStrategy$AntClassLoader2 @62c3180d)

Is it possible to configure a commentTrigger for each job in an organizationFolder using the Job DSL plugin?

Or is the plugin only meant to be used from within a pipeline ?

Thanks!

Additional Information

Name Version
pipeline-github 2.7
Jenkins 2.269
github-branch-source 2.9.2
@NFollett89
Copy link

NFollett89 commented May 4, 2021

We're seeing this problem with multi-branch Pipelines

multibranchPipelineJob('HelloWorld') {
    triggers {
        issueCommentTrigger {
            commentPattern("test")
        }
    }
    // ...
}

Error:

java.lang.ClassCastException: org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject cannot be cast to org.jenkinsci.plugins.workflow.job.WorkflowJob ...

This is very problematic because our Jenkinsfile sets a comment pattern it will trigger to, which is injected into the job configuration on the first run, but if we re-run our Job DSL pipeline to update/populate jobs, it will break the triggering on any GitHub Pull Requests we have open.

EDIT
This triggering configuration should be available for multibranchPipelineJob's, because it appears in the introspective Job DSL API reference specific to our instance
image

@renanqts
Copy link

Faced with the same issue using multibranchPipelineJob :(

@aaronwalker
Copy link
Member

@thorntonryan @NFollett89 @renanqts currently we don't support the JobDSL directly. You can try using the Configure block https://github.com/jenkinsci/job-dsl-plugin/blob/master/docs/The-Configure-Block.md

This is something we might add in the future though so I'll mark the as an enhancement. Also PRs welcome :)

@johnjelinek
Copy link

@aaronwalker: do you have an example config block for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants