如何将变量传递给 azure yaml 中的模板参数?
How to pass variables to the template parameter in azure yaml?
我有模板
dockerbuild.yml
steps:
- task: Bash@3
displayName: Build an image to container registry
inputs:
script : echo $(PATH)
然后是一个变量文件
var.build.yml
- name: PATH
value: 'docker/path'
- name: PATH1
value: 'docker/oldpath'
- name: PATH2
value: 'docker/newpath'
azurepipeline1.yml
resources:
repositories:
- repository: templates
type: git
name: components/pipeline_templates
trigger:
- none
pool:
name: PoolA
variables:
- template: variabletemplates/var.build.yml@templates
jobs:
steps:
- template: CI-CD/dockerbuild.yml@templates # Template reference
parameters:
PATH: ${{ variables.PATH }}
- template: CI-CD/dockerbuild.yml@templates # Template reference
parameters:
PATH: ${{ variables.PATH1 }}
- template: CI-CD/dockerbuild.yml@templates # Template reference
parameters:
PATH: ${{ variables.PATH2 }}
以上代码有效
但是如果我把参数改成
parameters:
PATH: ${{ variables.PATH1 }}
OR
parameters:
PATH: ${{ variables.PATH2 }}
在输出中显示
Output:
docker/path
$(PATH1)
$(PATH2)
我需要在具有不同路径的管道中多次重复使用模板。请帮助解决问题
您的模板需要 parameters
块。
parameters:
- name: PATH
type: string
steps:
- task: Bash@3
displayName: Build an image to container registry
inputs:
script : echo ${{ parameters.PATH }}
我有模板
dockerbuild.yml
steps:
- task: Bash@3
displayName: Build an image to container registry
inputs:
script : echo $(PATH)
然后是一个变量文件
var.build.yml
- name: PATH
value: 'docker/path'
- name: PATH1
value: 'docker/oldpath'
- name: PATH2
value: 'docker/newpath'
azurepipeline1.yml
resources:
repositories:
- repository: templates
type: git
name: components/pipeline_templates
trigger:
- none
pool:
name: PoolA
variables:
- template: variabletemplates/var.build.yml@templates
jobs:
steps:
- template: CI-CD/dockerbuild.yml@templates # Template reference
parameters:
PATH: ${{ variables.PATH }}
- template: CI-CD/dockerbuild.yml@templates # Template reference
parameters:
PATH: ${{ variables.PATH1 }}
- template: CI-CD/dockerbuild.yml@templates # Template reference
parameters:
PATH: ${{ variables.PATH2 }}
以上代码有效
但是如果我把参数改成
parameters:
PATH: ${{ variables.PATH1 }}
OR
parameters:
PATH: ${{ variables.PATH2 }}
在输出中显示
Output:
docker/path
$(PATH1)
$(PATH2)
我需要在具有不同路径的管道中多次重复使用模板。请帮助解决问题
您的模板需要 parameters
块。
parameters:
- name: PATH
type: string
steps:
- task: Bash@3
displayName: Build an image to container registry
inputs:
script : echo ${{ parameters.PATH }}