Class StepContext

  • All Implemented Interfaces:<Object>, Serializable

    public abstract class StepContext
    extends Object
    implements<Object>, Serializable
    An implicit context available to every Step. In a flow, would be created by a FlowExecution. It is serializable so a step which may survive a Jenkins restart is free to save it.

    StepContext is only valid until the result is set via FutureCallback. Beyond that point, callers are not allowed to call any of the methods.

    See Also:
    Serialized Form
    • Constructor Detail

      • StepContext

        public StepContext()
    • Method Detail

      • onSuccess

        public abstract void onSuccess​(@Nullable
                                       Object result)
        Specified by:
        onSuccess in interface<Object>
      • isReady

        public abstract boolean isReady()
        Whether get(java.lang.Class<T>) is ready to return values. May be called to break deadlocks during reloading.
        true normally, false if we are still reloading the context, for example during unpickling
      • saveState

        public abstract<Void> saveState()
        Requests that any state held by the StepExecution be saved to disk. Useful when a long-running step has changed some instance fields (or the content of a final field) and needs these changes to be recorded. An implementation might in fact save more state than just the associated step execution, but it must save at least that much.
        a future letting you know if and when the state was in fact saved
      • setResult

        public abstract void setResult​(Result r)
        Sets the overall result of the flow. Like Run.setResult(hudson.model.Result), can only make the result worse than it already is. Since some flows may have try-catch semantics, if a step fails to complete normally it is better to use FutureCallback.onFailure(Throwable) instead. (For example with FlowInterruptedException.)
        r - Result.UNSTABLE, typically
      • equals

        public abstract boolean equals​(Object o)
        StepContexts get persisted, so they may not have the identity equality, but equals method would allow two instances to be compared.
        equals in class Object
        true if StepContexts are for the same context for the same execution.
      • hashCode

        public abstract int hashCode()
        Needs to be overridden as the equals(Object) method is overridden.
        hashCode in class Object