Conditional Variables based on Environment #163562
-
Why are you starting this discussion?Question What GitHub Actions topic or product is this about?Misc Discussion DetailsHi all, I've been playing around with substituting variables based on conditions such as an environment Here i am replacing the var AWS ACCESS KEY ID for example with either prod access key or nonprod access key, this is working however i don't see it documented and am worried that this may not be something that would work in the future if it is no longer supported/depreciated - could anyone let me know if this is safe to continue to use and push? env: |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
|
What you're doing is clever and technically works today, but GitHub doesn't officially document or guarantee support for inline conditional logic inside ${{ }} expressions the way you’ve used it (like && and ||). A few notes: GitHub Actions expression syntax does support ternary logic, but it's safer to use the documented form: ${{ condition && 'value-if-true' || 'value-if-false' }} However, edge cases can break if the "true" value is falsey (like an empty string), which might cause the "false" value to get used instead. GitHub might change how it handles expressions or validation in the future — so relying on undocumented patterns does carry risk. Safer alternatives: For now, if this logic works for you and you've tested it well, it's probably okay short-term. But for long-term maintainability and team collaboration, I’d recommend moving toward a more explicit setup. |
Beta Was this translation helpful? Give feedback.
What you're doing is clever and technically works today, but GitHub doesn't officially document or guarantee support for inline conditional logic inside ${{ }} expressions the way you’ve used it (like && and ||).
A few notes:
GitHub Actions expression syntax does support ternary logic, but it's safer to use the documented form:
${{ condition && 'value-if-true' || 'value-if-false' }} However, edge cases can break if the "true" value is falsey (like an empty string), which might cause the "false" value to get used instead.
GitHub might change how it handles expressions or validation in the future — so relying on undocumented patterns does carry risk.
Safer alternatives:
Use if: conditions a…