Environment vars are not correctly evaluated in a jobs if condition #181396
Replies: 1 comment
-
|
💬 Your Product Feedback Has Been Submitted 🎉 Thank you for taking the time to share your insights with us! Your feedback is invaluable as we build a better GitHub experience for all our users. Here's what you can expect moving forward ⏩
Where to look to see what's shipping 👀
What you can do in the meantime 💻
As a member of the GitHub community, your participation is essential. While we can't promise that every suggestion will be implemented, we want to emphasize that your feedback is instrumental in guiding our decisions and priorities. Thank you once again for your contribution to making GitHub even better! We're grateful for your ongoing support and collaboration in shaping the future of our platform. ⭐ |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Why are you starting this discussion?
Bug
What GitHub Actions topic or product is this about?
Workflow Deployment
Discussion Details
I am trying to use github actions environment variables as as feature toggles to limit the deployment of certain features to certain environments during development without requiring hard-coding the feature toggle either in the workflow or within the code itself.
We have multiple environments, but for this example lets assume we only have a development (dev) and production environment, and each environment has a variable named "DEPLOY" which has a value of either "Y" or "N".
From my testing the condition can only be correctly evaluated if the variable is wrapped in the curly braces, e.g.
if: ${{ vars.DEPLOY }} == 'Y'. However it does not work if the curly braces are omitted (as it typical for a jobifcondition) or if the condition is wrapped in curly braces in its entirety.This behaviour is not intuitive, is not documented and appears to be a bug. I can only assume that the variable is not otherwise available at the time of evaluation of the job's
ifcondition, and the behaviour gets stranger if you try and combine it with other if conditions.e.g. given the following workflow, run on push on the test-feature-toggle branch, with the
DEPLOYvariable defined for thedevenvironment and set toY:Yields the following results:

Based on the documentation it would reasonably be assumed that most if not all of these conditions would evaluate to true.
Beta Was this translation helpful? Give feedback.
All reactions