Stack Exchange
Azure pipeline: Passing parameters to a template does not work when "condition: succeeded()" is in parameters
I simplified the problem.
There is a "print-parameters.yml" template to print all passed parameters.
steps:
- task: PowerShell@2
  displayName: 'Printing Parameters'
  
  inputs: 
    pwsh: true
    targetType: 'inline'
    script: |
      echo "${{ convertToJson(parameters) }}"
      

I call the template above inside the template below as an example and pass all parameters.
parameters:
  condition: succeeded()
 
steps:
- template: print-parameters.yml
  parameters:
    templateName: 'set-build-variables.yml'
    templateParameters: ${{parameters}}
   

Problem:
Passing the parameters as I did works well. The problem pops out when I add "condition: succeeded()" into parameters. I think convertToJson can not parse it.
My idea:
If I find a way to remove "condition: succeeded()" from the list of parameters before convertToJson, would solve it. Or, if I find a way to print parameters one-by-one in a loop and ignore "condition: succeeded()", would be another solution.
But I do not know how to do my ideas.

Parameters must contain a name and data type. To pass the parameter, please define the parameter data types and name as object in your YAML file. Then, using ${{parameters.myObject}} to pass the parameter to YAML template.
parameters:
- name: myObject
  type: object
  default:
    condition: succeeded()

trigger:
- main

extends:
  template: print-parameters.yml
  parameters:
    myObject: ${{parameters.myObject}}

Then, you can use the each keyword to loop through parameters with the object type in your YAML template. Please refer to each keyword.
parameters:
- name: myObject
  type: object
  default: []

stages:
- stage: test_stage
  jobs:
  - job: test_job
    steps:
    - ${{ each o in parameters.myObject }}:
        - script: echo "${{ o.key }}:${{ o.value }}"


Hello @Poodineh, have you tried to use ${{parameters.myObject}} to pass the parameter to YAML template and use the each keyword to print the parameters?

Thanks. It works. But when I run the pipeline, it shows each parameter in one step, and it makes a mess. Any idea to make all parameters printed in one step?
