help with workflow-step-api-plugin

18 views
Skip to first unread message

Denis Richtárik

unread,
May 16, 2018, 4:14:18 PM5/16/18
to jenkin...@googlegroups.com

Hello,

I am working on OpenStack Cloud plugin to introduce Declarative Pipeline option. The feature is nearly done, all I need is to delete the OpenStack machine which is supposed to be only temporary and removed once the job is finished.

I am not sure which method to call from Workflow step api plugin.

I have my Step Execution here: https://github.com/drichtarik/openstack-cloud-plugin/blob/JENKINS-47742/src/main/java/jenkins/plugins/openstack/pipeline/OpenStackNodeStepExecution.java

It needs to run ((JCloudsComputer) newSlave.toComputer()).deleteSlave(); as it is in public void stop method. But probably somewhere else? Should I extend something else than SynchronousNonBlockingStepExecution?

Your help would be much appreciated!


Regards

Denis  Richtárik

Jesse Glick

unread,
May 16, 2018, 5:10:29 PM5/16/18
to Jenkins Dev
On Wed, May 16, 2018 at 4:05 PM, Denis Richtárik
<denis.r...@gmail.com> wrote:
> It needs to run ((JCloudsComputer) newSlave.toComputer()).deleteSlave(); as
> it is in public void stop method. But probably somewhere else? Should I
> extend something else than SynchronousNonBlockingStepExecution?

`stop` will not be called at all typically, and I do not think you
meant for this to be a synchronous step: it looks quite likely to take
more than a trivial amount of time to run, and you need to do cleanup,
meaning that you want a block-scoped step which can do some work
(ideally asynchronously), then invoke its body, then do more work when
the body exits.

It is possible, though not simple, to write something very much like
what you are attempting; while I do not vouch for every detail, you
can look at

https://github.com/jenkinsci/docker-plugin/blob/554bbf8ab937611b17c2c20e9318dace5de3540f/src/main/java/io/jenkins/docker/pipeline/DockerNodeStepExecution.java#L54-L170

If this is a common use case, we could perhaps extract the difficult
boilerplate into some kind of utility in `workflow-durable-task-step`.

Much easier would be to avoid writing a Pipeline step at all, just
implementing `Cloud`, so that a plain old `node` block (perhaps with
some label expression) could be used.
Reply all
Reply to author
Forward
0 new messages