Syntax errors declaring conditional variables inside YAML jobs

Viewed 125

Trying to edit a function YAML file to include some conditional variables, but whatever I try the file won't seem to run in the pipeline.

The desired variable is an array, which I've tried declaring like this:

jobs: 
- deployment:                         Databases
  displayName:                        Deploy Databases in ${{ parameters.stage }}
  environment:                        '${{ parameters.stage }}.${{ parameters.serverName }}'
  timeoutInMinutes:                   2880  

  variables:
    ${{ if eq(parameters.MyParam, True) }}:
      MyArray: [ 'Bar' ]
    ${{ if ne(parameters.MyParam, True) }}:
      MyArray: [ 'Foo' ]

  stages: [ YAML continues ] 

But when trying to run the pipeline, I get the error:

A sequence was not expected

I've tried declaring it as a simple string variable instead, but that just gives a different error:

  variables:
    ${{ if eq(parameters.MyParam, True) }}:
      MyArray: 'Bar'
    ${{ if ne(parameters.MyParam, True) }}:
      MyArray: 'Foo'

Expected a sequence or mapping. Actual value '$(MyArray)'

Trying this syntax:

  variables:
    ${{ if eq(parameters.MyParam, True) }}:
      - name: MyArray
      value: 'Foo'
    ${{ if ne(parameters.MyParam, True) }}:
      - name: MyArray
      value: 'Bar'

Yields the error:

[path] (Line: 9, Col: 5): Expected a mapping [path]: Object reference not set to an instance of an object.

Trying this:

variables: - name: MyArray ${{ if eq(parameters.myParam, True) }}: value: 'Foo' ${{ if ne(parameters.myParam, True) }}: value: 'Bar'

Gets me the same errors as my initial attempts.

I've also tried simply declaring a variable without the conditional and that also gives the same original errors. What am I doing wrong here?

0 Answers
Related