Class CpsStepContext

java.lang.Object
org.jenkinsci.plugins.workflow.steps.StepContext
org.jenkinsci.plugins.workflow.support.DefaultStepContext
org.jenkinsci.plugins.workflow.cps.CpsStepContext
All Implemented Interfaces:
com.google.common.util.concurrent.FutureCallback<Object>, Serializable

public class CpsStepContext extends org.jenkinsci.plugins.workflow.support.DefaultStepContext
StepContext implementation for CPS.

This context behaves in two modes. It starts in the synchronous mode, where if a result is set (or exception is thrown), it just gets recoded. When passed into Step.start(StepContext), it's in this mode.

When Step.start(StepContext) method returns, we'll atomically check if the result is set or not and then switch to the asynchronous mode. In this mode, if the result is set, it'll trigger the rehydration of the workflow. If a CpsStepContext gets serialized, it'll be deserialized in the asynchronous mode.

This object must be serializable on its own without sucking in any of the CpsFlowExecution object graph. Wherever we need CpsFlowExecution we do that by following FlowExecutionOwner, and when we need pointers to individual objects inside, we use IDs (such as id}.

Author:
Kohsuke Kawaguchi
See Also:
  • Method Details

    • getStepDescriptor

      @CheckForNull public org.jenkinsci.plugins.workflow.steps.StepDescriptor getStepDescriptor()
      Obtains StepDescriptor that represents the step this context is invoking.
      Returns:
      This method returns null if the step descriptor used is not recoverable in the current VM session, such as when the plugin that implements this was removed. So the caller should defend against null.
    • getDisplayName

      public String getDisplayName()
    • getExecution

      protected CpsFlowExecution getExecution() throws IOException
      Specified by:
      getExecution in class org.jenkinsci.plugins.workflow.support.DefaultStepContext
      Throws:
      IOException
    • isReady

      public boolean isReady()
      Specified by:
      isReady in class org.jenkinsci.plugins.workflow.steps.StepContext
    • hasBody

      public boolean hasBody()
      Overrides:
      hasBody in class org.jenkinsci.plugins.workflow.steps.StepContext
    • newBodyInvoker

      public CpsBodyInvoker newBodyInvoker()
      Specified by:
      newBodyInvoker in class org.jenkinsci.plugins.workflow.steps.StepContext
    • newBodyInvoker

      @NonNull public CpsBodyInvoker newBodyInvoker(@NonNull org.jenkinsci.plugins.workflow.cps.BodyReference body, boolean unexport)
    • doGet

      protected <T> T doGet(Class<T> key) throws IOException, InterruptedException
      Specified by:
      doGet in class org.jenkinsci.plugins.workflow.support.DefaultStepContext
      Throws:
      IOException
      InterruptedException
    • getNode

      protected org.jenkinsci.plugins.workflow.graph.FlowNode getNode() throws IOException
      Specified by:
      getNode in class org.jenkinsci.plugins.workflow.support.DefaultStepContext
      Throws:
      IOException
    • onFailure

      public void onFailure(Throwable t)
    • onSuccess

      public void onSuccess(Object returnValue)
      Specified by:
      onSuccess in interface com.google.common.util.concurrent.FutureCallback<Object>
      Specified by:
      onSuccess in class org.jenkinsci.plugins.workflow.steps.StepContext
    • setResult

      public void setResult(Result r)
      Specified by:
      setResult in class org.jenkinsci.plugins.workflow.steps.StepContext
    • saveState

      public com.google.common.util.concurrent.ListenableFuture<Void> saveState()
      Specified by:
      saveState in class org.jenkinsci.plugins.workflow.steps.StepContext
    • equals

      public boolean equals(Object o)
      Specified by:
      equals in class org.jenkinsci.plugins.workflow.steps.StepContext
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in class org.jenkinsci.plugins.workflow.steps.StepContext
    • toString

      public String toString()
      Overrides:
      toString in class Object