1
parameters:
- name: environment
  type: string
  default: dev

- name: region
  type: string
  default: ${{ if or(eq(parameters.environment, 'dev'), eq(parameters.environment, 'tst')) }}central${{ else }}${{ if eq(parameters.environment, 'both') }}central, east${{ else }}east${{ endif }}${{ endif }}

I am putting condition as if the parameter environment is dev or test then the parameter region will be central and for other environments, the region will be central, east, both

But at the same time I am getting error as directive are not supported for the expression that are embedded

  • Is that the actual syntax you're using, including linebreaks and everything else? That doesn't look like it's valid. There's no `${{ endif }}`, for starters. Begin by reviewing the documentation on compile-time expressions. Beyond that, I don't think you can use compile-time expressions in parameters at all. – Daniel Mann Jun 28 '23 at 17:13
  • Thanks for correcting me out but its not work although as in parameter condition is not working. – vikash sharma Jun 29 '23 at 17:10

1 Answers1

1

I don't believe you can run an expression in a parameter. To achieve the desired behavior I think you'd rather run your expression to set a variable value based on the condition.

So it would be:

parameters:
- name: environment
  type: string
  default: dev

variables:
  ${{ if or(eq(parameters.environment, 'dev'), eq(parameters.environment, 'tst')) }}:
    region: 'central'
  ${{ if eq(parameters.environment, 'both') }} :
    region: 'central, east'
  ${{ else }} :
    region: 'east'

I have not tested this; however, this approach should work. You'd reference your region then as ${{ variables.region}} and can pass it along to future inputs/templates.

Here's a stackoverflow post as well that provides an example.

DreadedFrost
  • 2,602
  • 1
  • 11
  • 29