In my case I wanted to determine proper variable group based on a value of variable defined for specific pipeline. The goal was to avoid the need to have separate yml file for each environment. First, I tried following syntax:
variables:
- ${{ if eq(variables['EnvName'], 'prod') }}:
- group: prod
but if expression seems to be evaluated compile time and at that moment values of the variables are not yet set so it didn't work.
Instead I used one of the "build variables" which luckily are already set when if expression is processed. For me DefinitionName variable which returns the name of the build pipeline was a good candidate as I have environment specified in my pipelines' names:

This is what I used in the yml:
variables:
- ${{ if contains(variables['Build.DefinitionName'], 'testing') }}:
- group: testing-env-group
- ${{ elseif contains(variables['Build.DefinitionName'], 'staging') }}:
- group: staging-env-group
- ${{ elseif contains(variables['Build.DefinitionName'], 'production') }}:
- group: prod-env-group
env? in pipeline variables?