Hoping someone can help me with this as looking back at my git log I've now tried 14 different things to try to get this to work. Here's the scenario:
I created a variable in the UI called
deploy_custom_env
and checked "User can set variable at runtime." I initialized it to "default", but I am expecting users to override it when starting manual runs.I am trying to use this variable in the
condition
for some of my pipeline stages.I've tried many, many different things. Here are some examples:
First:
condition: ne(variables.deploy_custom_env, 'default')
And
condition: ne('${{ variables.deploy_custom_env }}', 'default')
And
variables:
- name: isCustomEnv
value: ne[($(deploy_custom_env), 'default')]
And even
variables:
- name: isCustomEnv
value: ne[(variables.deploy_custom_env, 'default')]
Hilariously, when trying to use the above, both of the following conditions result in skipped stages:
condition: eq(variables.isCustomEnv, true)
condition: eq(variables.isCustomEnv, false)
Does this mean it's both true
and false
? (I'm kidding, of course: I have no clue what this actually evaluates to.) I've also tried enabling System.debug
and checking "Enable system diagnostics"`, but when my stages get skipped, I can't really see what these variables are evaluating to.
I would appreciate any suggestions or documentation that will help me solve this problem. Surely this is something that people do? Also, recommendation for anyone from Azure reading: I would love to see this example in the documentation somewhere.
I looked at the following to try to answer this:
- https://docs.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops&tabs=yaml%2Cbatch#understand-variable-syntax
- https://docs.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml#build-variables-devops-services
- https://docs.microsoft.com/en-us/azure/devops/pipelines/process/conditions?view=azure-devops&tabs=yaml
- https://docs.microsoft.com/en-us/azure/devops/pipelines/process/expressions?view=azure-devops#conditionally-assign-a-variable
In the latter, I saw the difference between compile-time and runtime, with the following note:
The difference between runtime and compile time expression syntaxes is primarily what context is available. In a compile-time expression (${{ }}), you have access to parameters and statically defined variables. In a runtime expression ($[ ]), you have access to more variables but no parameters.
That seems related, but how do I translate this into something that works in my condition
s?