如何将参数值从模板 yaml 文件传递​​到主管道

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

当我在 azure devops 上尝试 运行 此管道时,我收到错误“意外 属性 RunChangeLogic”。我该如何解决这个问题?

它似乎不接受来自模板的参数EntryPoint.yaml。我还需要做什么吗?
很抱歉这样简单的问题。我对 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'   

我试过你的 yaml,它对我适用于以下 yaml。

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'   

更多信息请参考官方文档Template types & usage.


编辑: 从您的评论中,我了解到您有一个多阶段的 azure 管道。请参考这个stages.template definition.

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

这是我的阶段模板测试 yaml 文件。

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'