Pcornel
Browse topics
Options
Recent
Favorites
Automation · Technical reference

Conditional Execution

Direct answer

Conditional execution runs a step only when a condition is true, such as when: in Ansible or if: in GitHub Actions, skipping it otherwise.

When to use this

Use this when steps run only under conditions.

First 30 seconds

1. Conditional execution runs steps when conditions hold.

2. Simple, testable expressions.

3. Report skipped steps.

4. Avoid complex logic in workflow DSL.

5. Compute decisions in code if complex.

Operational verification

condition true → run step; false → skip

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
workflow conditional execution patterns
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

Platformworkflow conditional execution patterns · Automation implementations are tool and platform specific. Use the adjacent Domain for the technology being automated and this Domain for automation behavior.
Scope / prerequisiteUse this when steps run only under conditions.
What next?3 suggested next steps
Evidence1
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

3 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

Capture the concrete output, symptom, packet, log or counter before changing anything.

Step 1 Verification path Verify boundary

The primary procedure is: Execute fixtures that make the condition true, false and missing/invalid; capture the evaluated context and confirm the protected action runs only for the intended case. Exercise failure-oriented cases such as truthy string surprises, missing context, stale outputs from skipped dependencies, implicit success() behavior, condition evaluated at wrong scope and retry changing inputs unexpectedly so the test covers failure cases, not only the happy path.

Step 2 Common mistakes Narrow the fault
  • Conditions on unvalidated data.
Step 3 Where it fails Narrow the fault

Failure analysis for Workflow Automation → Conditional Execution should follow the path through the components: upstream outputs/status → condition context construction → expression evaluation → execute/skip decision → side effect → downstream status aggregation. Tests should include edge cases such as truthy string surprises, missing context, stale outputs from skipped dependencies, implicit success() behavior, condition evaluated at wrong scope and retry changing inputs unexpectedly. Recovery should retain evaluated inputs and expression result, fix the condition/context rather than forcing the step, rerun the same fixture and verify both execute and skip paths.

Evidence references

Evidence · 1 on this Topic

Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.

observation · 1
Key points
  • when: or if: decides whether a step runs.
  • Skipped steps should be logged.
  • Conditions use earlier outputs.
Key checks
  • Condition expressions — logic
  • Tests for each condition — coverage
  • Skipped step reporting — visibility
ReferenceWhy it matters1 section · depth on demand

In depth

Conditional execution runs a task only when a condition is true — for example only deploy if validation passed, or only notify on failure. It keeps workflows from doing unnecessary or unsafe work.

# GitHub Actions
- name: Deploy
  if: github.ref == 'refs/heads/main' && success()
  run: ./deploy.sh
# Ansible
- name: Reload nginx
  ansible.builtin.service: { name: nginx, state: reloaded }
  when: nginx_conf.changed
Common conditionUse
Previous step resultContinue only on success
Branch/environmentProduction only from main
Changed flagRestart only when config changed
Input valueOptional steps
ReferenceImportant terms & boundaries1 section · depth on demand

Mechanics

Conditional Execution in Workflow Automation is owned at runtime by the workflow engine evaluating a condition in the context of a specific run/job/step and available status/data values. The durable intent is versioned condition expression with explicit inputs, null/default semantics and the side-effecting step/job it gates. Reliable automation must carry stable identity across the path: workflow/run/job/step IDs plus expression/rule version and referenced input/context fields. The consumer-visible target is whether one bounded action is executed or skipped; skipped state must remain distinguishable from success. The key invariants are condition is evaluated in the intended context, missing values are explicit, prior failure/cancel status behavior is understood, and skipped actions cannot be mistaken for successful verification.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.
ReferenceConfiguration & state1 section · depth on demand

Lifecycle

Store and review versioned condition expression with explicit inputs, null/default semantics and the side-effecting step/job it gates; pin or at least record implementation/model versions and keep environment-specific identity outside reusable logic where possible. The stable identity contract is workflow/run/job/step IDs plus expression/rule version and referenced input/context fields.

Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Technical verification history

Verification history & basis

When and against what this Topic was checked. Later text edits do not count as a new check.

2026-09-14 · vendor docworkflow conditional execution patterns current

Authoritative/upstream documentation reviewed for bounded claims in Workflow Automation > Conditional Execution. Documentation verification only; this is not observed lab or production Evidence.

Basis: https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-syntax · confidence 94%
Embedded reference data

Quick lookup tables

Workflow Automation → Conditional Execution · operational reference

Context-specific ownership, verification, output and failure-boundary lookup for Workflow Automation → Conditional Execution.

LayerWorkflow Automation → Conditional Execution operational reference
Runtime/ownershipworkflow conditional execution patterns · the workflow engine evaluating a condition in the context of a specific run/job/step and available status/data values
Persistent intentversioned condition expression with explicit inputs, null/default semantics and the side-effecting step/job it gates
VerificationExecute fixtures that make the condition true, false and missing/invalid; capture the evaluated context and confirm the protected action runs only for the intended case.
Expected interpretationThe workflow marks skipped versus executed actions distinctly, the expression result is reproducible from recorded inputs, and only the true path can mutate the target.
Recovery boundaryretain evaluated inputs and expression result, fix the condition/context rather than forcing the step, rerun the same fixture and verify both execute and skip paths
Depth when you need it

Deep reference

Healthy vs suspicious evidence

Output interpretation

At minimum retain workflow/run/job/step IDs, condition text/version, sanitized input values, evaluated boolean/error, execute/skip status, downstream action ID and final target read-back. The useful output makes ambiguity visible, links to the target identity from workflow/run/job/step IDs plus expression/rule version and referenced input/context fields, and provides enough context to safely decide whether a retry is permitted.

Confirmation

Confirm action

Continue?