我正在尝试使用扩展作为管道的一部分。我正在尝试从Azure文档(例如
)开始进行第一步工作 # pythonparameter-template.yml
parameters:
- name: usersteps
type: stepList
default: []
steps:
- ${{ each step in parameters.usersteps }}
- ${{ step }}
# azure-pipelines.yml
trigger: none
resources:
repositories:
- repository: CI-CD-Templates
type: git
name: /CI-CD-Templates
ref: refs/heads/master
extends:
template: /pythonparameter-template.yml@CI-CD-Templates
parameters:
usersteps:
- script: echo This is my first step
- script: echo This is my second step
我不断收到以下错误:
在此情况下,不允许使用指令“每个”。嵌入在字符串中的表达式不支持伪指令。仅当整个值为表达式时才支持指令 意外值'$ {{parameters.usersteps}}中的每个步骤-$ {{step}}'
从模板扩展后,azure-pipelines.yml也可以有自己的自定义步骤,即
# azure-pipelines.yml
resources:
repositories:
- repository: templates
type: git
name: MyProject/MyTemplates
ref: tags/v1
extends:
template: template.yml@templates
parameters:
usersteps:
- script: echo This is my first step
- script: echo This is my second step
steps:
- template: /validation-template.yml@CI-CD-Templates
parameters:
commitMessage: $(commitMessage)
- template: /shared-template.yml@CI-CD-Templates
parameters:
buildArtifactDir: $(buildArtifactDir)
答案 0 :(得分:0)
更新
请在此DC链接中引用响应-Yaml extends feature erroring out when looping through steps.
YAML在#pythonparameter-template.yml中具有验证任务 注释掉这两行,您的YAML将成功。此处显示的模板阻止使用任何任务。对于具有特定安全要求的人来说,这可能是一个方案。
${{ if eq(pair.key, 'task') }}:
'${{ pair.value }}': error
您是否要在同一个文件中合并两个yml pythonparameter-template.yml
azure-pipelines.yml
?不支持。
parameters:
- name: usersteps
type: stepList
default: []
steps:
- ${{ each step in parameters.usersteps }}
- ${{ step }}
根据错误Directives are not supported for expressions that are embedded within a string. Directives are only supported when the entire value is an expression Unexpected value '${{ each step in parameters.usersteps }} - ${{ step }}'
您可能使用了错误的格式。关于格式,您可以在此处参考我们的官方文档- Template types & usage
此外,您可以使azure-pipelines.yml也具有其自己的自定义步骤。但是您需要将它们放在管道中的参数下,而不像您使用的方式那样。
azure-pipelines.yml
trigger:
- master
extends:
template: pythonparameter-template.yml
parameters:
buildSteps:
- bash: echo Test #Passes
displayName: succeed
- bash: echo "Test"
displayName: succeed
- script: echo "Script Test"
displayName: Fail