Class DurableTaskStep.Execution

java.lang.Object
org.jenkinsci.plugins.workflow.steps.StepExecution
org.jenkinsci.plugins.workflow.steps.AbstractStepExecutionImpl
org.jenkinsci.plugins.workflow.steps.durable_task.DurableTaskStep.Execution
All Implemented Interfaces:
Serializable, Runnable
Enclosing class:
DurableTaskStep

@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static final class DurableTaskStep.Execution extends org.jenkinsci.plugins.workflow.steps.AbstractStepExecutionImpl implements Runnable
Represents one task that is believed to still be running.

This step has two modes, based on pulling or pushing log content from an agent. In the default (push) mode, Controller.watch(hudson.FilePath, org.jenkinsci.plugins.durabletask.Handler, hudson.model.TaskListener) is used to ask the agent to begin streaming log content. As new output is detected at regular intervals, it is streamed to the TaskListener, which in the default StreamTaskListener implementation sends chunks of text over Remoting. When the process exits, exited(int, byte[]) is called and the step execution also ends. If Jenkins is restarted in the middle, onResume() starts a new watch task. Every DurableTaskStep.WATCHING_RECURRENCE_PERIOD, the controller also checks to make sure the process still seems to be running using Controller.exitStatus(hudson.FilePath, hudson.Launcher, hudson.model.TaskListener). If the agent connection is closed, ws will be stale (FilePath.channel will be Channel.isClosingOrClosed()) and so getWorkspace() called from check() will call getWorkspaceProblem(java.lang.Exception) and we will attempt to get a fresh ws as soon as possible, with a new watch. (The persisted node and remote identify the workspace.) If the process does not seem to be running after two consecutive checks, yet no explicit process completion signal was sent, awaitingAsynchExit will make the step assume that the watch task is broken and the step should fail. If sending output fails for any reason other than ChannelClosedException, problem(java.lang.Exception) will attempt to record the issue but permit the step to proceed.

In the older pull mode, available on request by DurableTaskStep.USE_WATCHING or when encountering a noncompliant Controller implementation, the controller looks for process output (Controller.writeLog(hudson.FilePath, java.io.OutputStream)) and/or exit status in check() at variable intervals, initially MIN_RECURRENCE_PERIOD but slowing down by RECURRENCE_PERIOD_BACKOFF up to MAX_RECURRENCE_PERIOD. Any new output will be noted in a change to the state of controller, which gets saved to the step state in turn. If there is any connection problem to the workspace (including controller restarts and Remoting disconnects), ws is nulled out and Jenkins waits until a fresh handle is available.

See Also:
  • Field Details

  • Method Details

    • start

      public boolean start() throws Exception
      Specified by:
      start in class org.jenkinsci.plugins.workflow.steps.StepExecution
      Throws:
      Exception
    • stop

      public void stop(@NonNull Throwable cause) throws Exception
      Overrides:
      stop in class org.jenkinsci.plugins.workflow.steps.StepExecution
      Throws:
      Exception
    • getStatus

      public String getStatus()
      Overrides:
      getStatus in class org.jenkinsci.plugins.workflow.steps.StepExecution
    • run

      public void run()
      Checks for progress or completion of the external task.
      Specified by:
      run in interface Runnable
    • exited

      public void exited(int exitCode, byte[] output) throws Exception
      Throws:
      Exception
    • problem

      public void problem(Exception x)
    • onResume

      public void onResume()
      Overrides:
      onResume in class org.jenkinsci.plugins.workflow.steps.AbstractStepExecutionImpl