A job sets 'env: TARGET: staging'. Which syntax correctly references TARGET inside a step 'if:' condition?
Select an answer to reveal the explanation.
Short Explanation and Infographic
Inside if: you must use the expression language and the env context: env.TARGET. Shell-style $TARGET works in run: scripts, not in if: expressions evaluated by the runner.
Full explanation below image
Full Explanation
Conditional expressions are evaluated by the GitHub Actions expression engine, not by the shell. Environment variables defined in env: blocks are exposed to expressions through the env context, so the correct form is env.TARGET (commonly wrapped as ${{ env.TARGET == 'staging' }}). The $TARGET shell form only expands inside run: script bodies after the runner starts the shell. vars.TARGET would look for a configuration variable named TARGET, not a job env entry. secrets.TARGET would look for a secret, which is wrong for a non-sensitive env value and secrets should not be used for simple configuration flags. Remember precedence: step env overrides job env overrides workflow env when the same name is defined at multiple levels.