Class StepExecution

    • Method Detail

      • getContext

        public StepContext getContext()
      • start

        public abstract boolean start()
                               throws Exception
        Start execution of something and report the end result back to the given callback.

        Arguments are passed when instantiating steps.

        This method will run in the CPS VM thread and as such should not perform I/O or block. Use SynchronousNonBlockingStepExecution or GeneralNonBlockingStepExecution as needed.

        true if the execution of this step has synchronously completed before this method returns. It is the callee's responsibility to set the return value via StepContext.onSuccess(Object) or FutureCallback.onFailure(Throwable). false if the asynchronous execution has started and that StepContext will be notified when the result comes in. (Note that the nature of asynchrony is such that it is possible for the StepContext to be already notified before this method returns.)
        Exception - if any exception is thrown, Step is assumed to have completed abnormally synchronously (as if FutureCallback.onFailure(java.lang.Throwable) is called and the method returned true.)
      • stop

        public void stop​(@NonNull
                         Throwable cause)
                  throws Exception
        May be called if someone asks a running step to abort.

        Just like Thread.interrupt(), the step might not honor the request immediately. Multiple stop requests might be sent. It is always responsible for calling StepContext.onSuccess(Object) or (more likely) FutureCallback.onFailure(Throwable) eventually, whether or not it was asked to stop.

        The default behavior is to call FutureCallback.onFailure(java.lang.Throwable) immediately. This may be overridden by non-block-scoped steps which wish to halt some processing prior to failing the step, or even to send a cancellation signal to some process but leave the step running until that is handled gracefully. Block-scoped steps which merely call their bodies generally need not override this method, as the interrupt will be sent to the step(s) actually running at the time (so no special call to BodyExecution.cancel(Throwable) is needed), though an override may be necessary if it is possible for there to be no body currently running.

        This method is meant to be used by FlowExecution, not called from UI or other human requests to pause. Use BodyExecution.cancel(Throwable) for programmatic cancellation of bodies.

        cause - Contextual information that lets the step know what resulted in stopping an executing step, passed in the hope that this will assist diagnostics.
      • onResume

        public void onResume()
        Called when StepExecution is brought back into memory after restart. Convenient for re-establishing the polling.

        Currently not permitted to throw exceptions, but may report errors via FutureCallback.onFailure(java.lang.Throwable).

        See Also:
      • getStatus

        public String getStatus()
        May be overridden to provide specific information about what a step is currently doing, for diagnostic purposes. Typical format should be a short, lowercase phrase. It should not be localized as this is intended for use by developers as well as users. May include technical details about Jenkins internals if relevant.
        current status, or null if unimplemented
        See Also:
        getStatusBounded(long, java.util.concurrent.TimeUnit)
      • getStatusBounded

        public final String getStatusBounded​(long timeout,
                                             TimeUnit unit)
        Like getStatus() but more robust. Waits a most a given amount of time for the result, and handles RuntimeExceptions.
        timeout - maximum amount of time to spend
        unit - time unit
      • applyAll

        public static<?> applyAll​(<StepExecution,​Void> f)
        Apply the given function to all the active running StepExecutions in the system.
        Future object that signals when the function application is complete.
        See Also:
      • applyAll

        public static <T extends StepExecution><?> applyAll​(Class<T> type,
                                                                                                     <T,​Void> f)
        Applies only to the specific subtypes.