Problem injecting Step into Execution

22 views
Skip to first unread message

Dan Jasek

unread,
Sep 9, 2016, 12:57:32 PM9/9/16
to Jenkins Developers
I am working on a Pipeline compatible plugin with a build step.  I implemented an AbstractStepImpl for the step definition and an associated AbstractSynchronousNonBlockingStepExecution.
The problem I am running into is that I cannot get a reference to the Step in the Execution.  I have a private transient field annotated with @Inject just like other similar plugins.
However, the step field is null when the Execution is run.

Here is a gist with the two relevant classes:  https://gist.github.com/oillio/125ccbc6b976b4368605c0feadc48557

Anyone have a suggestion on what I am doing wrong?

Or even a way I can debug the problem further?
As the problem is in the magic of DI, I have hit a brick wall on where to go from here.

Jesse Glick

unread,
Sep 9, 2016, 1:55:41 PM9/9/16
to Jenkins Dev
On Fri, Sep 9, 2016 at 12:57 PM, Dan Jasek <d...@jasek.org> wrote:
> Anyone have a suggestion on what I am doing wrong?

Do not see anything obvious wrong. I would start by getting rid of
Lombok here, as a likely source of risk. Or set a breakpoint in
`AbstractStepImpl.prepareInjector`.

> As the problem is in the magic of DI, I have hit a brick wall on where to go
> from here.

You are not obliged to use DI. Just extend `Step` and `StepDescriptor`
directly, and your `Step.start` can call whatever constructor you like
of the execution. You can still extend
`AbstractSynchronousNonBlockingStepExecution` to pick up its
background thread semantics; just call the `super` constructor taking
`StepContext`. For context parameters, call `StepContext.get`, and
list them in `getRequiredContext`. Really it is not much more code
than the DI version, and a lot easier to understand and debug. Kohsuke
is just enamored of Guice. :-/

Dan Jasek

unread,
Sep 12, 2016, 12:13:17 AM9/12/16
to Jenkins Developers
Thanks for the pointers, they helped me track down the problem to a dependency issue.  One of my non Jenkins dependencies included an incompatible version of Guice.
Reply all
Reply to author
Forward
0 new messages