What does the 'if' conditional in a GitHub Actions job or step do?
Select an answer to reveal the explanation.
Short Explanation and Infographic
The 'if' conditional is GitHub Actions' gatekeeper. Use it to skip steps when tests fail, run cleanup only on failure, or restrict deployments to specific branches. It evaluates GitHub context expressions and controls whether a step even runs.
Full explanation below image
Full Explanation
The 'if' conditional in GitHub Actions is an expression that determines whether a job or step should execute. It evaluates GitHub Actions expressions that can reference: (1) Context variables (github.ref, github.event_name, github.actor), (2) Job outcome functions (success(), failure(), cancelled(), always()), (3) Environment variables and inputs. Common patterns: 'if: github.ref == refs/heads/main' (only run on main branch), 'if: failure()' (only run cleanup step if previous step failed), 'if: github.event_name == pull_request' (only run on PR events), 'if: contains(github.actor, bot)' (skip for bot actors). The expression must evaluate to true for the job/step to execute. False or empty results skip execution.