MSFT在文档中共享的扩展模板示例假定该步骤失败了,但并未失败。 https://docs.microsoft.com/en-us/azure/devops/pipelines/process/templates?view=azure-devops#extend-from-a-template
任何人都可以分享一个可行的示例。
我想验证扩展模板中的用户yaml并在构建步骤失败的情况下使构建失败,
答案 0 :(得分:1)
此处的文档提供了混乱的方向。您可以尝试下载不会按照预期方式运行的构建日志,然后分析initializeLog.txt
文件的内容。此处列出了所有key
个评估表达式。
尝试以下示例:
start.yml
# File: start.yml
parameters:
- name: buildSteps # the name of the parameter is buildSteps
type: stepList # data type is StepList
default: [] # default value of buildSteps
stages:
- stage: secure_buildstage
pool: Hosted VS2017
jobs:
- job: secure_buildjob
steps:
- script: echo This happens before code
displayName: 'Base: Pre-build'
- script: echo Building
displayName: 'Base: Build'
- ${{ each step in parameters.buildSteps }}:
- ${{ each pair in step }}:
${{ if ne(pair.value, 'CmdLine@2') }}:
${{ pair.key }}: ${{ pair.value }}
${{ if eq(pair.value, 'CmdLine@2') }}:
'${{ pair.value }}': error
- script: echo This happens after code
displayName: 'Base: Signing'
azure-pipelines.yml
trigger:
- master
extends:
template: start.yml
parameters:
buildSteps:
- bash: echo Test #Passes
displayName: succeed
- bash: echo "Test"
displayName: succeed
- script: echo "Script Test"
displayName: Fail
然后您将看到由于检测到script
步骤而导致管道失败:
注意:此验证是,一旦模板检测到从CmdLine@2
传递了一个azure-pipeline.yml
步骤,它将使当前管道失败,而不是一个指定步骤。