Using the DSL on an ExtensionPoint - can I create my own ExtensibleContext?

73 views
Skip to first unread message

Dan Alvizu

unread,
Feb 1, 2016, 2:32:44 PM2/1/16
to job-dsl-plugin
Hi,

I attempted to add job-dsl support for my plugin, the jira-ext-plugin:


The big feature of the jira-ext-plugin is that it is meant to be extended. There is a single build step:


And both fields (IssueStrategyExtension, JiraOperationExtension) are capable of being extended. I have DSL for the operations I provide:


However, a feature of my plugin is that if you want to extend it for whatever custom operation you want to do, expose that as an ExtensionPoint. I'd like them to be able to use the job-dsl plugin as well. It's just not clear to me how to do that. I think I need to define an ExtensibleContext, but it's not clear to me if that is something I can do, as a plugin author, or if it needs to go into job-dsl code.

Is there an example of how to do that?

I guess another question: if I can't do that, can I at least define my own configure block?




Daniel Spilker

unread,
Feb 5, 2016, 12:02:31 PM2/5/16
to job-dsl...@googlegroups.com
Hi Dan,

yes, you need to define an ExtensibleContext and you can do it from a plugin. See PublisherContext for an example:

https://github.com/jenkinsci/job-dsl-plugin/blob/job-dsl-1.42/job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/helpers/publisher/PublisherContext.groovy

The best option is to subclass AbstractExtensibleContext and then implement addExtensionNode(Node).

Daniel

--
You received this message because you are subscribed to the Google Groups "job-dsl-plugin" group.
To unsubscribe from this group and stop receiving emails from it, send an email to job-dsl-plugi...@googlegroups.com.
To post to this group, send email to job-dsl...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/job-dsl-plugin/66fa3a35-7fde-406b-b196-67a06ce18f92%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dan Alvizu

unread,
Feb 5, 2016, 7:06:33 PM2/5/16
to job-dsl...@googlegroups.com
Hi Daniel,

Thanks for the reply.

I'm having trouble implementing this using PublisherContext as an example.

I desire to have a DSL like this:

job {

  steps {
    updateJiraExt {
      issueStrategy {
         firstWordOfCommit()      // <-- Can be contributed by other plugins
      }
      jiraOperations {
        addComment("foo", true);  // <-- Can be contributed by other plugins
        addLabel("bar")           // <-- Can be contributed by other plugins
      }
    }
  }
}

Since my plugin is a BuildStep, I provide a ContextExtensionPoint under StepContext:


@Extension(optional=true)
public class ContextExtensionPointImpl
extends ContextExtensionPoint
implements Context
{
@DslExtensionMethod(context = StepContext.class)
public Object updateJiraExt(Runnable closure) {
UpdateJiraExtContext context = new UpdateJiraExtContext();
executeInContext(closure, context);
JiraExtBuildStep buildStep = new JiraExtBuildStep(context.issueStrategy, context.extensions);
return buildStep;
}
}

This seems different than PublisherContext, because it is part of the job-dsl plugin itself.

I want to have two ExtensibleContexts - one for IssueStrategy, one for JiraOperations. So I made those extend from ExtensibleContext:


However, I can't instantiate those from UpdateJiraExtContext, because it must extend ContextExtensionPoint:


This doesn't seem to be a problem for PublisherContext, because it is directly instantiated, for example by Job, where it has access to all of this stuff:


Is there a way I can get around this?

Thanks!


--
You received this message because you are subscribed to a topic in the Google Groups "job-dsl-plugin" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/job-dsl-plugin/ycfReHd_3WY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to job-dsl-plugi...@googlegroups.com.

To post to this group, send email to job-dsl...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Ping Identity logo
Dan Alvizu
Sr. Development Engineer
Ping Identity
@ dal...@pingidentity.com
phone +1 720.317.2060
twitter @pingidentity
Connect with us!
pingidentity.com
twitter logo twitter logo youtube logo LinkedIn logo Facebook logo Google+ logo slideshare logo rss feed icon

CIS 2016

Daniel Spilker

unread,
Feb 12, 2016, 4:18:17 AM2/12/16
to job-dsl...@googlegroups.com
Ah, OK. I see. You need to get access to javaposse.jobdsl.dsl.JobManagement and javaposse.jobdsl.dsl.Item. That's currently not possible. I'll fix that and come back to you.

Daniel

Daniel Spilker

unread,
Feb 12, 2016, 5:09:58 AM2/12/16
to job-dsl...@googlegroups.com

Dan Alvizu

unread,
Feb 12, 2016, 12:32:27 PM2/12/16
to job-dsl...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages