我的 YAML 文件已经包含资源部分,现在我想向资源部分添加一个管道,以在 PR 管道成功后触发我的发布管道。这工作正常,并且当合并到主分支时会触发管道
以下是目前的相关部分
trigger:
- main
---------- removed parameter and variable sections for brevity -----------
resources:
repositories:
- repository: templates
type: git
name: OneBranch.Pipelines/GovernedTemplates
ref: refs/heads/main
基于这样的几篇 SO 帖子:Azure Devops - 如何从另一个管道调用一个管道
我修改了 YAML:
trigger:
- none
---------- removed parameter and variable sections for brevity -----------
resources:
repositories:
- repository: templates
type: git
name: OneBranch.Pipelines/GovernedTemplates
ref: refs/heads/main
pipelines:
- pipeline: DRIContactManagement-Official
source: DRIContactManagement-PullRequest
trigger: true
当我运行修改后的 YAML 时,管道失败并出现错误:
(Line: 14, Col: 1): Did not find expected <document start>.
行号位于“触发器”正下方。
有什么建议可以解决这个问题吗?
更新: 要回答 @brightran 的问题,这里是 YAML 的完整部分
#################################################################################
# Pipelines - Official
#
# This pipeline was created from a sample located at:
#
# https://aka/obpipelines/easystart/samples #
# Documentation: https://aka/obpipelines #
# Yaml Schema: https://aka/obpipelines/yaml/schema #
# Retail Tasks: https://aka/obpipelines/tasks #
# Support: https://aka/onebranchsup #
#################################################################################
trigger:
- none
parameters: # parameters are shown up in ADO UI in a build queue time
- name: 'debug'
displayName: 'Enable debug output'
type: boolean
default: false
variables:
CDP_DEFINITION_BUILD_COUNT: $[counter('', 0)] # needed for onebranch.pipeline.version task https://aka.ms/obpipelines/versioning
system.debug: ${{ parameters.debug }}
ENABLE_PRS_DELAYSIGN: 1
ROOT: $(Build.SourcesDirectory)
REPOROOT: $(Build.SourcesDirectory)
OUTPUTROOT: $(REPOROOT)\out
NUGET_XMLDOC_MODE: none
WindowsContainerImage: 'onebranch.azurecr.io/windows/ltsc2019/vse2022:latest' # Docker image which is used to build the project https://aka/obpipelines/containers
resources:
repositories:
- repository: templates
type: git
name: OneBranch.Pipelines/GovernedTemplates
ref: refs/heads/main
pipelines:
- pipeline: DRIServiceUpdate-Official # Name of the pipeline resource.
source: DRIServiceUpdate-PullRequest # The name of the pipeline referenced by this pipeline resource.
#project: # Required only if the source pipeline is in another project
trigger: true # Run app-ci pipeline when any run of security-lib-ci completes
第 14 行对应于
Parameters:
部分的开始。构建中没有其他错误或日志。我尝试在 Azure DevOps 中编辑 YAML 文件,以便在保存更改时它会进行验证,但它始终显示其有效结构。我还尝试通过一些在线验证器运行它并得到相同的结果。
尝试检查以下事项来解决问题:
检查 YAML 文件中的缩进。通常,子项相对于父项缩进两个空格。如果子项目以“
- <keyName>:
”开头(例如,- name: myVar
),则可以忽略缩进。您尝试像下面一样更新您的 YAML。
trigger: none
parameters:
- name: debug
displayName: 'Enable debug output'
type: boolean
default: false
variables:
CDP_DEFINITION_BUILD_COUNT: $[counter('', 0)]
system.debug: ${{ parameters.debug }}
ENABLE_PRS_DELAYSIGN: 1
ROOT: $(Build.SourcesDirectory)
REPOROOT: $(Build.SourcesDirectory)
OUTPUTROOT: $(REPOROOT)\out
NUGET_XMLDOC_MODE: none
WindowsContainerImage: 'onebranch.azurecr.io/windows/ltsc2019/vse2022:latest'
resources:
repositories:
- repository: templates
type: git
name: OneBranch.Pipelines/GovernedTemplates
ref: refs/heads/main
pipelines:
- pipeline: DRIServiceUpdate-Official
source: DRIServiceUpdate-PullRequest
trigger: true
检查 YAML 文件的编码。如果尝试将编码更改为UTF-8 Without BOM(
UTF-8
)。您可以将 YAML 文件下载到本地计算机,并在文本编辑器(如 VS Code、Notepad++、EmEditor 等)上打开它们...然后使用编码 UTF-8 Without BOM 重新保存 YAML 文件。然后将更新的 YAML 文件推送回 Azure Repos。