Generalization of parallel special-casing in Pipeline DSL?

20 views
Skip to first unread message

Andrew Bayer

unread,
Mar 10, 2016, 8:24:42 PM3/10/16
to jenkin...@googlegroups.com
So https://github.com/jenkinsci/workflow-plugin/blob/30a80b44ef524333165ed59b25de30daf1b2a99d/cps/src/main/java/org/jenkinsci/plugins/workflow/cps/DSL.java#L116 - right now, the parallel step is the only step that can act as a container for further steps without having those further steps directly specified as a closure argument to the step. How would we go about generalizing this?

I ask because for what I'm working on currently, I want to be able to take a declarative data structure in closure form as an argument and then construct and execute Pipeline from that. I'm writing this as a Step, so I believe I need to be put in the right bucket in the section I linked to above, and if my Step doesn't have a body and isn't ParallelStep, it gets put in the atomic node bucket. That's not where it needs to end up, I don't think.

So I've got two thoughts on how to work around this and I'm not sure if either of them is at all wise and/or sane, hence emailing for advice:

- Scenario 1: Change ParallelStep (and its DescriptorImpl accordingly) to extend a new abstract Step that we then use for the check I linked to above. Then my Step can do the same thing and tada! Theoretically.

- Scenario 2: Pass the closure argument to my Step as a body after all, but rather than the normal approach of calling "newBodyInvoker()" in the StepExecution start method (i.e., like https://github.com/jenkinsci/workflow-plugin/blob/53e756588642a39d4e2c74590c317f0a904b26b1/basic-steps/src/main/java/org/jenkinsci/plugins/workflow/steps/RetryStepExecution.java#L18-L20), instead process the "body" I got passed and generate a new closure to serve as the actual body to execute, resulting in a call more like https://github.com/jenkinsci/workflow-plugin/blob/18624a0af5492c51b47291fddf456ce61a84a974/cps/src/main/java/org/jenkinsci/plugins/workflow/cps/steps/ParallelStepExecution.java#L52-L58.

Advice? Thoughts? Halp? =)

A.

Jesse Glick

unread,
Mar 10, 2016, 10:23:56 PM3/10/16
to Jenkins Dev
On Thu, Mar 10, 2016 at 8:24 PM, Andrew Bayer <andrew...@gmail.com> wrote:
> Advice?

Do not touch any of this, and write your functionality as a Groovy
library, using low-level `Step`s as needed for logical processing.
`ParallelStep` is very special—that is why it is implemented in the
same plugin as the CPS engine itself.
Reply all
Reply to author
Forward
0 new messages