P.T
P.T

Reputation: 59

How to pass parameters value from a template yaml file to main pipeline

when i try to run this pipeline on azure devops, i got the error "Unexpected property RunChangeLogic". How can I troubleshoot this?

It seems it doesn't accept the parameter from the template EntryPoint.yaml. Is there anything else I need to do?
sorry for the simple question like this. I am completely new to Azure Devops

EntryPoint.yaml:

parameters:

  - name: RunChangeLogic  
    displayName: Run change logic  
    type: boolean  
    default: false  
....

Azure_pipeline.yaml:

trigger: none  

pool:  
  vmImage: 'ubuntu-latest'  

stages:  
  - template: "YamlTemplates/Stage/Entrypoint.yaml"  
    parameters:  
       RunChangeLogic: 'true'   

Upvotes: -1

Views: 13644

Answers (1)

Miao Tian-MSFT
Miao Tian-MSFT

Reputation: 5652

I tried your yaml and it works for me with following yaml.

enter image description here

Entrypoint.yaml:

parameters:

  - name: RunChangeLogic  
    displayName: Run change logic  
    type: boolean  
    default: false  

steps:
- script: echo ${{ parameters.RunChangeLogic }}

Azure_pipeline.yaml:

trigger: none  

pool:  
  vmImage: 'ubuntu-latest'  

extends:
   template: "YamlTemplates/Stage/Entrypoint.yaml"  
   parameters:  
       RunChangeLogic: 'true'   

For more info please refer the official Doc Template types & usage.


Edit: From your comment, I understand that you have a multi stage azure pipeline. Please refer to this stages.template definition.

You can define a set of stages in one file and use it multiple times in other files.

Here is my test yaml files for stages template.

Entrypoint.yaml:

parameters:

  - name: RunChangeLogic  
    displayName: Run change logic  
    type: boolean  
    default: false  

stages:
- stage: Teststage1
  jobs:
  - job: ${{ parameters.RunChangeLogic }}_testjob1
    steps:
    - script: echo ${{ parameters.RunChangeLogic }}
- stage: Teststage2
  jobs:
  - job: ${{ parameters.RunChangeLogic }}_testjob2
    steps:
    - script: echo ${{ parameters.RunChangeLogic }}

Azure_pipeline.yaml:

trigger: none  

pool:  
  vmImage: 'ubuntu-latest'  

stages:
- template: "YamlTemplates/Stage/Entrypoint.yaml"  
  parameters: 
    RunChangeLogic: 'true'

Upvotes: 2

Related Questions