Canceling a workflow¶
You can cancel a workflow run that is in progress. When you cancel a workflow run, the orchestrator cancels all jobs and steps that are part of that workflow.
Canceling a workflow run¶
-
Using the OpenTestFactory CLI, list the running workflow runs:
opentf-ctl get workflows
WORKFLOW_ID STATUS NAME <workflow_id_1> RUNNING Test Orchestrator with No Initial Environments <workflow_id_2> DONE Workflow end-to-end
-
Cancel the workflow run:
opentf-ctl kill workflow <workflow_id_1>
Killing workflow <workflow_id_1>.
Steps the orchestrator takes to cancel a workflow run¶
When canceling a workflow run, you may be running other software that uses resources that are related to the workflow run. To help you free up resources related to the workflow run, it may help to understand the steps the orchestrator performs to cancel a workflow run.
-
To cancel the workflow run, the orchestrator re-evaluates
if
conditions for all currently running jobs. If the condition evaluates totrue
, the job will not get canceled. For example, the conditionif: always()
would evaluate to true and the job continues to run. When there is no condition, that is the equivalent of the conditionif: success()
, which evaluates tofalse
for a cancelled workflow. -
For jobs that continue to run, the orchestrator re-evaluates
if
conditions for the unfinished steps. If the condition evaluates totrue
, the step continues to run. You can use thecancelled()
expression to apply a status check to the step. For more information, see “Expressions.” -
For jobs that need to be cancelled, the orchestrator waits for the completion of the currently running
run
step. It then marks the job as cancelled and re-evaluatesif
conditions for the unfinished steps. Steps that do not use thealways()
orcancelled()
status check will be skipped.Composite steps (
uses
steps) are treated as a single unit. Consider the following:steps: ... - uses: acme/my-action@v2 # -> with: # - run: echo 'foo' ... # - run: echo 'bar' ...
If the workflow is cancelled while the
run: echo 'foo'
step is running, the orchestrator will cancel theacme/my-action@v2
step and skip therun: echo 'bar'
step.Conversely, for the following:
steps: ... - uses: acme/my-action@v2 # -> with: # - run: echo 'foo' ... # - run: echo 'bar' if: always() ...
If the workflow is cancelled while the
run: echo 'foo'
step is running, due to thealways()
condition, the orchestrator will wait for the completion of theacme/my-action@v2
step before cancelling the workflow. In particular, therun: echo 'bar'
step will run.