Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does DSL extension in Jenkins plugin work

I want to create DSL extension for my Jenkins plugin (built using maven) just like in the example of Docker plugin for Jenkins. I see that the groovy file Docker.groovy is in: src/main/resources/org/jenkinsci/plugins/docker/workflow/Docker.groovy

Does this groovy file have to be within org.jenkinsci.plugin.docker.workflow, or can I just put it inside resources? What is the difference?

Also, If I define my DSL extension within the groovy file in this manner is the DSL extension available to call implicitly in the pipeline file?

like image 848
Rijo Simon Avatar asked Dec 12 '17 00:12

Rijo Simon


1 Answers

In order to make a step available in the Pipeline DSL through your plugin, you need to define a subclass of Step that performs the needed task. This can be completely done within Java, and is the preferred method for adding expanding the Pipeline DSL within a Jenkins plugin.

The Docker example you linked is unusual in this instance, and doesn't define a typical Pipeline DSL step (the docker directive in Pipeline functions like a cross between an agent, a step and a context block). Furthermore, it appears to include a Java class that loads the Groovy script dynamically, which acts as the entry point into the directive.

Groovy can be used to expand the Pipeline DSL; however this is done within the context of a shared library, which is meant to be more of a boilerplate reducing tool to be used internally.

like image 170
cstarner Avatar answered Oct 27 '22 10:10

cstarner