stages.stage の定義

ステージは、関連するジョブのコレクションです。 既定では、ステージは順番に実行されます。 dependsOn プロパティで他のことが指定されていない限り、各ステージは前のステージが完了した後でのみ開始します。

stages:
- stage: string # Required as first property. ID of the stage.
  displayName: string # Human-readable name for the stage.
  pool: string | pool # Pool where jobs in this stage will run unless otherwise specified.
  dependsOn: string | [ string ] # Any stages which must complete before this one.
  condition: string # Evaluate this condition expression to determine whether to run this stage.
  variables: variables | [ variable ] # Stage-specific variables.
  jobs: [ job | deployment | template ] # Jobs which make up the stage.
  lockBehavior: string # Behavior lock requests from this stage should exhibit in relation to other exclusive lock requests.
  templateContext: # Stage related information passed from a pipeline when extending a template.
stages:
- stage: string # Required as first property. ID of the stage.
  displayName: string # Human-readable name for the stage.
  pool: string | pool # Pool where jobs in this stage will run unless otherwise specified.
  dependsOn: string | [ string ] # Any stages which must complete before this one.
  condition: string # Evaluate this condition expression to determine whether to run this stage.
  variables: variables | [ variable ] # Stage-specific variables.
  jobs: [ job | deployment | template ] # Jobs which make up the stage.

この定義を参照する定義: ステージ

プロパティ

stage 文字列。 最初のプロパティとして必須。
ステージの ID。

displayName 文字列。
ステージの人間が判読できる名前。

poolプール
特に指定がない限り、このステージのジョブが実行されるプール。

dependsOn string |文字列リスト。
このステージの前に完了する必要があるステージ。 既定では、ステージはパイプラインで定義されている順序で順番に実行されます。 パイプラインの前のステージに依存しないステージを指定 dependsOn: [] します。

condition 文字列。
この条件式を評価して、このステージを実行するかどうかを判断します。

variables変数
ステージ固有の変数。

jobsジョブ
ステージを構成するジョブ。

lockBehavior 文字列。
このステージからの動作ロック要求は、他の排他ロック要求に関連して発生する必要があります。 sequential |runLatest。

templateContext templateContext。
テンプレートを拡張するときにパイプラインから渡されるステージ関連情報。 の詳細については templateContext、「 拡張 YAML パイプライン テンプレートをステージ、ジョブ、デプロイのコンテキスト情報を渡せるようになりました」およびテンプレート - templateContext を使用してプロパティをテンプレートに渡す」を参照してください。

解説

ステージが実行するタイミングを手動で制御するには、承認チェックを使います。 これらのチェックは一般に、運用環境へのデプロイを制御するために使用されます。

チェックは、"リソース所有者" が使用できるメカニズムです。 これは、パイプライン内のステージがリソースをいつ消費するかを制御します。 環境などのリソースの所有者は、そのリソースを消費するステージを開始する前に必要なチェックを定義できます。

現在、環境では手動承認チェックがサポートされています。 詳細については、承認に関するページを参照してください。

排他ロック

YAML パイプラインでは、 保護されたリソースに対するステージの実行を制御するためにチェックが使用されます。 使用できる一般的なチェックの 1 つは、排他ロック チェックです。 このチェックでは、パイプラインからの実行を 1 つだけ続行できます。 複数の実行が同時に環境にデプロイしようとすると、チェックは古い実行をすべて取り消し、最新の実行のデプロイを許可します。

2 つの値を持つ プロパティを使用してlockBehavior、排他ロック チェックの動作を構成できます。

  • runLatest - 最新の実行のみが、リソースへのロックを取得します。 が指定されていない lockBehavior 場合、これは既定値です。
  • sequential - すべての実行で、保護されたリソースに対して順番にロックが取得されます。

リリースが累積的で、以前の実行からのコード変更がすべて含まれている場合は、古い実行をキャンセルすることをお勧めします。 ただし、コードの変更が累積されないパイプラインがいくつかあります。 プロパティを lockBehavior 構成すると、すべての実行を環境に順番に展開したり、以前の実行を取り消して最新の実行のみを許可したりする以前の動作を維持することを選択できます。 の sequential 値は、すべての実行が保護されたリソースに対して順番にロックを取得することを意味します。 の runLatest 値は、最新の実行のみがリソースへのロックを取得することを意味します。

sequential デプロイまたは runLatest で排他ロックのチェックを使用するには、次の手順に従います。

  1. 環境 (または別の保護されたリソース) で排他ロックのチェックを有効にします。
  2. パイプラインの YAML ファイルで、 という lockBehavior名前の新しいプロパティを指定します。 これは、パイプライン全体または特定のステージに対して指定できます。

ステージに設定する場合:

stages:
- stage: A
  lockBehavior: sequential
  jobs:
  - job: Job
    steps:
    - script: Hey!

パイプラインに設定する場合:

lockBehavior: runLatest
stages:
- stage: A
  jobs:
  - job: Job
    steps:
    - script: Hey!

次の例では、3 つのステージを 1 つずつ実行します。 中間のステージでは、2 つのジョブを並列に実行します。

stages:
- stage: Build
  jobs:
  - job: BuildJob
    steps:
    - script: echo Building!
- stage: Test
  jobs:
  - job: TestOnWindows
    steps:
    - script: echo Testing on Windows!
  - job: TestOnLinux
    steps:
    - script: echo Testing on Linux!
- stage: Deploy
  jobs:
  - job: Deploy
    steps:
    - script: echo Deploying the code!

この例では、2 つのステージを並列に実行します。 簡潔にするため、ジョブとステップは省略されています。

stages:
- stage: BuildWin
  displayName: Build for Windows
- stage: BuildMac
  displayName: Build for Mac
  dependsOn: [] # by specifying an empty array, this stage doesn't depend on the stage before it

関連項目

ステージ条件変数の詳細を理解してください。