次の方法で共有


resources.pipelines.pipeline definition

成果物を生成する 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 します。
既定の成果物を取得するためにパイプラインに必要なタグの一覧です。 随意;は、手動トリガーまたはスケジュールされたトリガーにのみ使用されます。

resources.pipelines.pipeline.triggertriggerします。
無効にするには none を指定し、すべての分岐を含める場合は true を指定するか、次の例で説明するように完全な構文を使用します。

注釈

pipeline: パイプライン リソースの名前を指定します。 パイプライン リソース変数の使用や成果物のダウンロードなど、パイプラインの他の部分からパイプライン リソースを参照する場合は、ここで定義されているラベルを使用します。

パイプライン リソース トリガーの stagestags の詳細については、パイプライン完了トリガー を参照してください。

パイプライン リソース トリガーの詳細については、パイプライン完了トリガーの を参照してください。

パイプライン リソース トリガーの構文

パイプライン完了トリガーでは、手動ビルドとスケジュールされたビルド 設定に Default ブランチを使用して、別のパイプラインの完了の結果としてパイプラインを実行するかどうかを決定するときに評価する 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

詳細については、「パイプライン完了トリガー する」を参照してください。

重要

リソース トリガーを定義するときに、そのパイプライン リソースが現在のパイプラインと同じリポジトリからのものである場合、トリガーはイベントが発生したのと同じブランチとコミットに従います。 ただし、パイプライン リソースが別のリポジトリからの場合、手動ビルドとスケジュールされたビルド 設定に対して、 Default ブランチで指定されたブランチで現在のパイプラインがトリガーされます。 詳細については、パイプライン完了トリガーに関するBranch に関する考慮事項を参照してください。

定義済み変数としてのパイプライン リソース メタデータ

各実行で、パイプライン リソースのメタデータは、次の定義済み変数としてすべてのジョブで使用できます。 これらの変数は実行時にパイプラインで使用できるため、パイプラインのコンパイル時に評価される テンプレート式では使用できません。

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

パイプライン リソースの 1 つによってパイプラインがトリガーされると、前の一覧の変数に加えて、次の変数が設定されます。

変数 価値
Build.Reason ResourceTrigger
Resources.TriggeringAlias 前の例の source-pipeline など、パイプライン リソースの名前。
Resources.TriggeringCategory pipeline

次の例には、2 つのパイプライン リソースがあります。

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です。

2 番目の bash タスクは、このセクションで説明するパイプライン リソース変数を含め、タスクで使用できるすべての環境変数を出力します。 環境変数の一覧表示は通常、運用パイプラインでは行われませんが、トラブルシューティングに役立ちます。 この例には 2 つのパイプライン リソースがあり、出力には次の 2 行が含まれています。

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/*

こちらもご覧ください