Class StepContext
- java.lang.Object
-
- org.jenkinsci.plugins.workflow.steps.StepContext
-
- All Implemented Interfaces:
com.google.common.util.concurrent.FutureCallback<Object>
,Serializable
public abstract class StepContext extends Object implements com.google.common.util.concurrent.FutureCallback<Object>, Serializable
An implicit context available to everyStep
. In a flow, would be created by aFlowExecution
. 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 viaFutureCallback
. Beyond that point, callers are not allowed to call any of the methods.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description StepContext()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract boolean
equals(Object o)
StepContext
s get persisted, so they may not have the identity equality, but equals method would allow two instances to be compared.abstract <T> T
get(Class<T> key)
Tries to find a contextually available object.boolean
hasBody()
Checks if this step was called with a body.abstract int
hashCode()
Needs to be overridden as theequals(Object)
method is overridden.abstract boolean
isReady()
Whetherget(java.lang.Class<T>)
is ready to return values.abstract BodyInvoker
newBodyInvoker()
Prepares for an asynchronous invocation of the body block that's given as an argument to this step invocation (in a host language dependent manner.)abstract void
onSuccess(Object result)
abstract com.google.common.util.concurrent.ListenableFuture<Void>
saveState()
Requests that any state held by theStepExecution
be saved to disk.abstract void
setResult(Result r)
Sets the overall result of the flow.
-
-
-
Method Detail
-
get
@Nullable public abstract <T> T get(Class<T> key) throws IOException, InterruptedException
Tries to find a contextually available object. Some types known to be in use:Launcher
- a way to fork processes
EnvVars
- read access to environment variables associated with a run, typically used for launchers
FilePath
- a “workspace” to use for example as from
Launcher.ProcStarter.pwd(hudson.FilePath)
Computer
- an agent we are running on
Executor
- an executor slot on an agent we are running on
TaskListener
- a place to send output (see
LogAction
for a flow) Run
- a running build
FlowExecution
- a running flow
FlowNode
- a running node in a flow
- Parameters:
key
- the kind of thing we want- Returns:
- that service, if available (which it should be if
StepDescriptor.getRequiredContext()
includes it), else null - Throws:
IOException
- IfStepContext
gets serialized, Jenkins restarts, deserialized later, andStep
tries to get additional context objects, it can be that the correspondingFlowExecution
could be non-existent (for example, the run that was driving the flow could have failed to load.) This exception is thrown in such situations just likeFlowExecutionOwner.get
throws IOException.InterruptedException
- See Also:
BodyInvoker.withContext(java.lang.Object)
,DynamicContext
-
onSuccess
public abstract void onSuccess(@Nullable Object result)
- Specified by:
onSuccess
in interfacecom.google.common.util.concurrent.FutureCallback<Object>
-
isReady
public abstract boolean isReady()
Whetherget(java.lang.Class<T>)
is ready to return values. May be called to break deadlocks during reloading.- Returns:
- true normally, false if we are still reloading the context, for example during unpickling
-
saveState
public abstract com.google.common.util.concurrent.ListenableFuture<Void> saveState()
Requests that any state held by theStepExecution
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.- Returns:
- 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. LikeRun.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 useFutureCallback.onFailure(Throwable)
instead. (For example withFlowInterruptedException
.)- Parameters:
r
-Result.UNSTABLE
, typically
-
newBodyInvoker
public abstract BodyInvoker newBodyInvoker() throws IllegalStateException
Prepares for an asynchronous invocation of the body block that's given as an argument to this step invocation (in a host language dependent manner.)When the block is completed normally or abnormally, you can have have the callback invoked. The invocation will not get scheduled until you start it.
StepDescriptor.takesImplicitBlockArgument()
must be true.- Throws:
IllegalStateException
- ifhasBody()
is false
-
hasBody
public boolean hasBody()
Checks if this step was called with a body.- Returns:
- true if
StepDescriptor.takesImplicitBlockArgument()
is true, and such a body was in fact passed in; false otherwise
-
equals
public abstract boolean equals(Object o)
StepContext
s get persisted, so they may not have the identity equality, but equals method would allow two instances to be compared.- Overrides:
equals
in classObject
- Returns:
- true if
StepContext
s are for the same context for the same execution.
-
hashCode
public abstract int hashCode()
Needs to be overridden as theequals(Object)
method is overridden.
-
-