How do we extend the Jenkins workflow dsl?

704 views Asked by At

If I'm working on a plugin and want to switch from using a step like so:

step([$class: 'Gradle', 
           switches: "-PenableInstallerDistribution=true",
           tasks: 'build install',
           gradleName: '(Default)',
           useWrapper: true,
           makeExecutable: true,
           fromRootBuildScriptDir: true,
           useWorkspaceAsHome: true])

to a nice dsl element like so:

gradle switches: "-PenableInstallerDistribution=true",
       tasks: 'build install',
       gradleName: '(Default)',
       useWrapper: true,
       makeExecutable: true,
       fromRootBuildScriptDir: true,
       useWorkspaceAsHome: true

and perhaps most importantly, show up in the snippet generator, what do I do? I've looked through what docs I could find, but still can't locate any advice on extending the dsl.

1

There are 1 answers

3
Jesse Glick On BEST ANSWER

First of all, if you are not really customizing the step configuration beyond omitting step, then this is probably a waste of time since a future revision of Workflow core is likely to include syntactic sugar for “metasteps” like step, checkout, and (now) wrap. (And any SimpleBuildStep already shows up in the Snippet Generator under step.)

That said, if you do need to create a first-class step, you would need to add a plugin dependency on workflow-step-api, and typically extend AbstractStepImpl, AbstractStepDescriptorImpl, and AbstractStepExecutionImpl.

If you are attempting to implement JENKINS-27393 then I would say that a useful implementation needs to wait for the infrastructural JENKINS-26055, as merely wrapping the existing Gradle builder will not allow the flow to survive a Jenkins restart (or slave disconnection) in the middle of this step.