1

When I run the pipeline the UI shows specific field to collect the input and run the template based on the condition. I am trying to get the parameter and convert it to variable and use it in my condition.

paramerers:
  - name: environment
    type: string
    default: ''

variables:
   environment : $(environment) 

Trying to run a template based on condition. The conditional variable is set through an API During Queue time

stages:
   - ${{ if eq(variables['environment'], 'test') }}:
      - template: azure-test-template.yml
    - ${{ if eq(variables['environment'], 'prod') }}:
      - template: azure-prod-template.yml

The template is never Executed irrespective of the value set in environment

is this a bug or is there something i'm not doing right?

Nish
  • 69
  • 6
  • try defining your variable like that: `environment : ${{ parameters.environment }}`. Why not using the parameter directly in your condition ? – Thomas Aug 31 '21 at 08:04
  • As I am getting variables over an API so can't pass parameters directly to my condition – Nish Aug 31 '21 at 12:02

1 Answers1

0

The $(variable) syntax is for variable resolution, not parameter resolution.

To access a parameter, you need to use the appropriate syntax: ${{ parameters.environment }} or ${{ parameters['environment'] }}

Daniel Mann
  • 57,011
  • 13
  • 100
  • 120
  • I agree, if am passing parameters in run-time this approach works good. However I have declared parameters as UI shows specific field to collect the input as the data coming from an API and the API provides me variables in queue time. So I have used the variable syntax to execute the respective template. However it fails to capture the queue time variable in the condition. Is there any other approach to this – Nish Aug 31 '21 at 03:42
  • 2
    Parameters and run-time variables behave very differently. Parameters are evaluated as part of template compilation, whereas run-time variables are evaluated **after** template compilation, and will only work in a very narrow set of circumstances. In this case, you can't conditionally load a template based on a run-time variable, because the YAML document has to be compiled into a final form (including one of those two templates) *before* the variables are evaluated. – Daniel Mann Aug 31 '21 at 04:01