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.
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.

參考此定義的定義: resources.pipelines

屬性

pipeline 字串。 作為第一個屬性的必要專案。
管線資源的識別碼。 可接受的值:[-_A-Za-z0-9]*。

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

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

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

branch 字串。
要挑選成品的分支。 選;預設為所有分支,僅用於手動或排程的觸發程式。

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

triggerresources.pipelines.pipeline.trigger
請指定 none 來停用、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 上一個範例中的名稱。
Resource.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.variableANY_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/*

另請參閱