Use this when steps run only under conditions.
Conditional Execution
Conditional execution runs a step only when a condition is true, such as when: in Ansible or if: in GitHub Actions, skipping it otherwise.
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.
condition true → run step; false → skip
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
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 · 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.
- when: or if: decides whether a step runs.
- Skipped steps should be logged.
- Conditions use earlier outputs.
- 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 condition | Use |
|---|---|
| Previous step result | Continue only on success |
| Branch/environment | Production only from main |
| Changed flag | Restart only when config changed |
| Input value | Optional 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.
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
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
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%Quick lookup tables
Workflow Automation → Conditional Execution · operational reference
Context-specific ownership, verification, output and failure-boundary lookup for Workflow Automation → Conditional Execution.
| Layer | Workflow Automation → Conditional Execution operational reference |
|---|---|
| Runtime/ownership | workflow conditional execution patterns · the workflow engine evaluating a condition in the context of a specific run/job/step and available status/data values |
| Persistent intent | versioned condition expression with explicit inputs, null/default semantics and the side-effecting step/job it gates |
| Verification | 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. |
| Expected interpretation | The 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 boundary | 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 |
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.