Azure devops: How to add a parameter to a step in a steplist

Viewed 89

I have a template which takes a steplist which will only be ran in a certain scenario. In part of the template the stepList can be used as is, but in another part I need to add a condition so it doesn't run if not applicable. What I have tried is (condition is more complicated actually but I've tried this too):

- ${{ each step in parameters.preDeleteSteps }}:
  - ${{ each pair in step }}:
      ${{ pair.key }}: ${{ pair.value }}
  condition: succeeded()

But this fails with:

/steps/terraform.yml@templates (Line: 132, Col: 7): Expected a mapping
/steps/terraform.yml@templates (Line: 131, Col: 7): Expected at least one key-value pair in the mapping
/steps/terraform.yml@templates: Unexpected state while attempting to read the mapping end. State:

MappingState:
  IsStart: True
  Index: 0
  IsKey: False
  IsEnd: False

SequenceState:
  IsStart: False
  Index: 2
  IsEnd: False

IfExpressionState:
  IsSequenceInsertion: True
  IsStart: False

MappingState:
  IsStart: False
  Index: 0
  IsKey: True
  IsEnd: False

SequenceState:
  IsStart: False
  Index: 6
  IsEnd: False

MappingState:
  IsStart: False
  Index: 0
 [...]

I have tried various approaches like putting the condition in [{}], putting a dash in front of it, putting it first after the each step but all seem to end in error. Does anyone know how to do this?

EDIT: Removed the actual condition I'm using as it's not relevant. I've tried with the condition above and that fails with the same error.

1 Answers
trigger:
- none

pool:
  vmImage: ubuntu-latest

parameters:
- name: mySteplist
  type: stepList
  default:
    - task: PowerShell@2
      name: test1
      inputs:
        targetType: 'inline'
        script: |
          # Write your PowerShell commands here.
          
          Write-Host "Hello World1"
    - task: PowerShell@2
      name: test2
      inputs:
        targetType: 'inline'
        script: |
          # Write your PowerShell commands here.
          
          Write-Host "Hello World2"
        

jobs:
- job:
  displayName: testjobname
  steps:
  - ${{ each step in parameters.mySteplist }}: # Each step
    - ${{ each pair in step }}:
        ${{ pair.key }}: ${{ pair.value }}
      condition: eq(1,2) # contional expression here

And this works on my side:

enter image description here

Related