共用方式為


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 字串。 做為第一個屬性的必要屬性。
管線資源的標識碼。 可接受的值:[-_A-Za-z0-9]*。

project 字串。
來源 專案;預設為目前的專案。

source 字串。
產生成品的管線名稱。 如果管線包含在資料夾中,請包含資料夾名稱,包括前置 \,例如 \security pipelines\security-lib-ci。 此屬性不區分大小寫,如果名稱包含空格,則不需要引號。 如果有多個具有相同名稱的管線,則必須指定資料夾路徑。

version 字串。
要挑選成品的管線執行編號,預設會在所有階段中成功執行最新的管線;僅適用於手動或排程的觸發程式。

branch 字串。
分支以挑選成品。 自選;默認為所有分支,僅用於手動或排程觸發程式。

tags 字串清單。
管線上取得預設成品所需的標籤清單。 自選;僅適用於手動或排程的觸發程式。

trigger resources.pipelines.pipeline.trigger
指定無停用、true 以包含所有分支,或使用完整的語法,如下列範例所述。

備註

備註

pipeline: 指定管線資源的名稱。 從管線的其他部分參考管線資源時,請使用此處定義的標籤,例如使用管線資源變數或下載成品時。

如需管線資源觸發程式中 stagestags 的詳細資訊,請參閱 管線完成觸發程式。

如需管線資源觸發程式的詳細資訊,請參閱 管線完成觸發程式。

管線資源觸發程式語法

備註

管線完成觸發程式會針對手動和排程的組建使用 預設分支, 設定來判斷哪一個分支版本的 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

這很重要

如果管線資源沒有指定的 projectName 值,則 project 不存在變數中。 project 屬性對於參考相同專案中管線的管線資源而言是選擇性的,但可能視需要指定。

以管線資源的標識碼取代 <Alias>。 針對下列管線資源,要存取 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 工作會輸出名為 projectName的管線資源 source-pipeline,也就是 FabrikamFiber

第二個 bash 工作會輸出工作可用的所有環境變數,包括本節所述的管線資源變數。 列出環境變數通常不會在生產管線中完成,但對於疑難解答很有用。 在此範例中,有兩個管線資源,而輸出包含下列兩行。

RESOURCES_PIPELINE_OTHER-PROJECT-PIPELINE_PROJECTNAME=FabrikamRepo
RESOURCES_PIPELINE_SOURCE-PIPELINE_PROJECTNAME=FabrikamFiber

備註

系統與使用者定義變數會插入為平台的環境變數。 當變數轉換成環境變數時,變數名稱會變成大寫,而句點會變成底線。 例如,變數名稱 any.variable 會變成 ANY_VARIABLE

如需使用變數和變數語法的詳細資訊,請參閱 瞭解變數語法指定條件表達式

您可以使用 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/*

另請參閱