resources.pipelines.pipeline 定义
如果有一个生成项目的 Azure Pipeline,则管道可以通过定义管道资源来使用项目。 在 Azure DevOps Server 2020 及更高版本中,还可以使用管道资源启用 管道完成触发器。
pipelines:
- pipeline: string # Required as first property. ID of the pipeline resource.
project: string # Project for the source; defaults to current project.
source: string # Name of the pipeline that produces the artifact.
version: string # The pipeline run number to pick the artifact, defaults to latest pipeline successful across all stages; used only for manual or scheduled triggers.
branch: string # Branch to pick the artifact. Optional; defaults to all branches, used only for manual or scheduled triggers.
tags: [ string ] # List of tags required on the pipeline to pickup default artifacts. Optional; used only for manual or scheduled triggers.
trigger: # Specify none to disable, true to include all branches, or use the full syntax as described in the following examples.
enabled: boolean # Whether the trigger is enabled; defaults to true.
branches: branches # Branches to include or exclude for triggering a run.
stages: [ string ] # List of stages that when matched will trigger the pipeline.
tags: [ string ] # List of tags that when matched will trigger the pipeline.
pipelines:
- pipeline: string # Required as first property. ID of the pipeline resource.
project: string # Project for the source; defaults to current project.
source: string # Name of the pipeline that produces the artifact.
version: string # The pipeline run number to pick the artifact, defaults to latest pipeline successful across all stages; used only for manual or scheduled triggers.
branch: string # Branch to pick the artifact. Optional; defaults to all branches, used only for manual or scheduled triggers.
tags: [ string ] # List of tags required on the pipeline to pickup default artifacts. Optional; used only for manual or scheduled triggers.
trigger: # Specify none to disable, true to include all branches, or use the full syntax as described in the following examples.
enabled: boolean # Whether the trigger is enabled; defaults to true.
branches: branches # Branches to include or exclude for triggering a run.
引用此定义的定义:resources.pipelines
性能
pipeline
字符串。 必需为第一个属性。
管道资源的 ID。 可接受的值:[-_A-Za-z0-9]*。
project
字符串。
源的项目;默认为当前项目。
source
字符串。
生成项目的管道的名称。 如果管道包含在文件夹中,请包含文件夹名称,包括前导 \
,例如 \security pipelines\security-lib-ci
。 此属性不区分大小写,如果名称包含空格,则不需要引号。 如果有多个具有相同名称的管道,则必须指定文件夹路径。
version
字符串。
管道运行编号以选取项目,默认为跨所有阶段成功的最新管道;仅用于手动或计划的触发器。
branch
字符串。
分支来选取项目。 自选;默认为所有分支,仅用于手动或计划触发器。
tags
字符串列表。
管道上用于提取默认项目所需的标记列表。 自选;仅用于手动或计划的触发器。
trigger
resources.pipelines.pipeline.trigger。
指定“不禁用”、“true”以包括所有分支或使用完整语法,如以下示例中所述。
注解
注释
pipeline:
指定管道资源的名称。 在引用管道其他部分的管道资源时(例如使用管道资源变量或下载项目时),请使用此处定义的标签。
有关管道资源触发器中的 stages
和 tags
的详细信息,请参阅 管道完成触发器。
有关管道资源触发器的详细信息,请参阅 管道完成触发器。
管道资源触发器语法
注释
管道完成触发器使用 默认分支进行手动生成和计划生成 设置,以确定哪个分支版本的 YAML 管道的分支筛选器在确定是否因另一个管道完成而运行管道时进行评估。 默认情况下,此设置指向存储库的默认分支。 有关详细信息,请参阅 管道完成触发器 - 分支注意事项。
可通过多种方式在管道资源中定义触发器。 若要在引用的管道的任何运行完成时触发运行,请使用 trigger: true
。
resources:
pipelines:
- pipeline: source-pipeline
source: TriggeringPipeline
trigger: true
若要禁用管道资源触发器,请指定 none
值。
resources:
pipelines:
- pipeline: source-pipeline
source: TriggeringPipeline
trigger: none
若要配置分支筛选器,请使用完整的语法。 可以将分支筛选器指定为要包含的分支列表,也可以指定为要包含的分支列表,以及要排除的分支列表。
若要指定要包含和排除的分支列表,请使用以下 trigger
语法。
resources:
pipelines:
- pipeline: source-pipeline
source: TriggeringPipeline
trigger:
branches:
include:
- main
- develop
- features/*
exclude:
- features/experimental/*
若要指定要包含的分支列表(不含排除),请省略 exclude
值,或使用以下语法指定要直接在 branches
后包括的分支列表。
resources:
pipelines:
- pipeline: source-pipeline
source: TriggeringPipeline
trigger:
branches:
- main
- develop
若要按阶段或标记进行筛选,请使用以下 trigger
语法。
resources:
pipelines:
- pipeline: source-pipeline
source: TriggeringPipeline
trigger:
branches: # Branches to include
tags: # List of tags that when matched will trigger the pipeline.
- release25
stages: # List of stages that when complete will trigger the pipeline.
- build
有关详细信息,请参阅 管道完成触发器。
重要
定义资源触发器时,如果其管道资源来自与当前管道相同的存储库,则触发时会遵循引发事件的同一分支并提交。 但是,如果管道资源来自不同的存储库,则当前管道在 默认分支指定的分支上触发,用于手动生成和计划生成 设置。 有关详细信息,请参阅 分支注意事项,了解管道完成触发器。
管道资源元数据作为预定义变量
在每个运行中,管道资源的元数据可供所有作业作为以下预定义变量使用。 这些变量在运行时可供管道使用,因此不能在 模板表达式中使用(在管道编译时计算)。
resources.pipeline.<Alias>.projectName
resources.pipeline.<Alias>.projectID
resources.pipeline.<Alias>.pipelineName
resources.pipeline.<Alias>.pipelineID
resources.pipeline.<Alias>.runName
resources.pipeline.<Alias>.runID
resources.pipeline.<Alias>.runURI
resources.pipeline.<Alias>.sourceBranch
resources.pipeline.<Alias>.sourceCommit
resources.pipeline.<Alias>.sourceProvider
resources.pipeline.<Alias>.requestedFor
resources.pipeline.<Alias>.requestedForID
重要
如果管道资源未指定 project
值,则变量中不存在 projectName
。 对于引用同一项目中的管道资源的管道资源,project
属性是可选的,但可根据需要指定。
将 <Alias>
替换为管道资源的 ID。 对于以下管道资源,访问 runID
的变量 resources.pipeline.source-pipeline.runID
。
resources:
pipelines:
- pipeline: source-pipeline
source: TriggeringPipeline
当管道由其中一个管道资源触发时,除了上一个列表中的变量之外,还会设置以下变量。
变量 | 价值 |
---|---|
Build.Reason |
ResourceTrigger |
Resources.TriggeringAlias |
管道资源的名称,例如上一示例中的 source-pipeline 。 |
Resources.TriggeringCategory |
pipeline |
以下示例有两个管道资源。
resources:
pipelines:
- pipeline: source-pipeline
source: PipelineTriggerSource
project: FabrikamFiber
trigger: true
- pipeline: other-project-pipeline
source: PipelineTriggerFromOtherProject
project: FabrikamRepo
trigger: true
trigger: none # Only trigger with pipeline resource trigger
pool:
vmImage: ubuntu-latest
- bash: echo $(resources.pipeline.source-pipeline.projectName)
- bash: printenv | sort
运行此管道时,第一个 bash
任务将输出名为 source-pipeline
的管道资源的 projectName
,即 FabrikamFiber
。
第二个 bash
任务输出可用于该任务的所有环境变量,包括本节中所述的管道资源变量。 列出环境变量通常不是在生产管道中完成的,但它可用于故障排除。 在此示例中,有两个管道资源,输出包含以下两行。
RESOURCES_PIPELINE_OTHER-PROJECT-PIPELINE_PROJECTNAME=FabrikamRepo
RESOURCES_PIPELINE_SOURCE-PIPELINE_PROJECTNAME=FabrikamFiber
可以使用 download
任务从管道资源使用项目。 请参阅 steps.download 关键字。
例子
resources:
pipelines:
- pipeline: MyAppA
source: MyCIPipelineA
- pipeline: MyAppB
source: MyCIPipelineB
trigger: true
- pipeline: MyAppC
project: DevOpsProject
source: MyCIPipelineC
branch: releases/M159
version: 20190718.2
trigger:
branches:
include:
- main
- releases/*
exclude:
- users/*