我正试图使用extends作为我的管道的一部分。我试图从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
我一直收到以下错误信息。
在此上下文中不允许使用'each'指令。不支持在字符串中嵌入表达式的指令。只有当整个值是一个表达式时才支持指令。 意外值'${{参数.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)
你是否试图将两个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 }}'
你可能用错了格式。关于格式,你可以参考我们的官方文档------。模板类型& 使用
此外,你可以让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