schedules.cron 定義

スケジュールされたトリガーは、ブランチがビルドされるスケジュールを指定します。

schedules:
- cron: string # Required as first property. Cron syntax defining a schedule in UTC time.
  displayName: string # Optional friendly name given to a specific schedule.
  branches: # Branch names to include or exclude for triggering a run.
    include: [ string ] # List of items to include.
    exclude: [ string ] # List of items to exclude.
  batch: boolean # Whether to run the pipeline if the previously scheduled run is in-progress; the default is false.
  always: boolean # Whether to always run the pipeline or only if there have been source code changes since the last successful scheduled run; the default is false.
schedules:
- cron: string # Required as first property. Cron syntax defining a schedule in UTC time.
  displayName: string # Optional friendly name given to a specific schedule.
  branches: # Branch names to include or exclude for triggering a run.
    include: [ string ] # List of items to include.
    exclude: [ string ] # List of items to exclude.
  always: boolean # Whether to always run the pipeline or only if there have been source code changes since the last successful scheduled run; the default is false.

この定義を参照する定義: スケジュール

Properties

cron 文字列。 最初のプロパティとして必須。
スケジュールを UTC 時刻で定義する Cron 構文。

displayName 文字列。
特定のスケジュールに指定されたオプションのフレンドリ名。

branchesincludeExcludeFilters
実行をトリガーするために含める、または除外するブランチ名。

batchboolean
以前にスケジュールされた実行が進行中の場合にパイプラインを実行するかどうか。既定値は です false。 これは、パイプライン リポジトリのバージョンに関係なく行われます。

次の表では、方法とbatch対話方法alwaysについて説明します。

常時 Batch 動作
false false パイプラインは、最後に成功したスケジュールされたパイプラインの実行に関して変更がある場合にのみ実行されます。
false true パイプラインは、最後に成功したスケジュールされたパイプラインの実行に関して変更があり、進行中のスケジュールされたパイプラインの実行がない場合にのみ実行されます。
true false パイプラインは、cron スケジュールに従って実行されます。
true true パイプラインは、cron スケジュールに従って実行されます。

重要

trueの場合always、 が であっても、batchtrueパイプラインは cron スケジュールに従って実行されます。

alwaysboolean
パイプラインを常に実行するか、前回のスケジュールされた実行以降にソース コードの変更があった場合にのみ実行するか。既定値は false です。

解説

スケジュールされたトリガーを指定しないと、スケジュールされたビルドは発生しません。

Note

branches に対して include 句を指定せずに exclude 句を指定することは、include 句で * を指定することと同じです。

重要

パイプライン設定 UI を使って定義されたスケジュールされたトリガーは、YAML でスケジュールされたトリガーより優先されます。

YAML パイプラインに YAML スケジュール トリガーと UI 定義のスケジュール トリガーの両方がある場合、UI 定義のスケジュール トリガーのみが実行されます。 YAML パイプラインで YAML 定義のスケジュール トリガーを実行するには、パイプライン設定 UI で定義されているスケジュール トリガーを削除する必要があります。 UI のスケジュールされたトリガーがすべて削除されたら、YAML のスケジュールされたトリガーの開始が評価されるには、プッシュを行う必要があります。

UI のスケジュールされたトリガーの YAML パイプラインからの削除については、「UI の設定で YAML のスケジュールされたトリガーをオーバーライドする」をご覧ください。

Build.CronSchedule.DisplayName 変数

cron スケジュールされたトリガーが原因でパイプラインが実行されている場合、定義済みの Build.CronSchedule.DisplayName 変数には、パイプラインの実行をトリガーした cron スケジュールの が含まれます displayName

YAML パイプラインには複数の cron スケジュールが含まれている場合があり、どの cron スケジュールを実行するかに基づいて、パイプラインで異なるステージまたはジョブを実行できます。 たとえば、夜間ビルドと毎週のビルドがあり、夜間ビルド中にのみ特定のステージを実行する必要があるとします。 ジョブまたはステージの Build.CronSchedule.DisplayName 条件で 変数を使用して、そのジョブまたはステージを実行するかどうかを決定できます。

- stage: stage1
  # Run this stage only when the pipeline is triggered by the 
  # "Daily midnight build" cron schedule
  condition: eq(variables['Build.CronSchedule.DisplayName'], 'Daily midnight build')

その他の例については、次の 例に関するセクションを 参照してください。

次の例では、2 つのスケジュールを定義します。

1 つ目のスケジュール Daily midnight build では、最後の正常なスケジュールされた実行以降にコードが変更された場合にのみ、毎日午前 0 時にパイプラインが実行されます。 main と、releases/ancient/* の下のブランチを除くすべての releases/* ブランチに対して、パイプラインが実行されます。

2 つ目のスケジュール Weekly Sunday build では、すべての releases/* ブランチで、日曜日の正午にパイプラインが実行されます。 前回の実行以降にコードが変更されたかどうかに関係なく行われます。

schedules:
- cron: '0 0 * * *'
  displayName: Daily midnight build
  branches:
    include:
    - main
    - releases/*
    exclude:
    - releases/ancient/*
- cron: '0 12 * * 0'
  displayName: Weekly Sunday build
  branches:
    include:
    - releases/*
  always: true

スケジュールされたトリガーによってスケジュールされたかどうかに基づいてステージまたはジョブを条件付きで実行するには、条件で 変数を Build.CronSchedule.DisplayName 使用します。 この例では、stage1パイプラインがスケジュールによってトリガーされた場合にのみ が実行されjob3、パイプラインがスケジュールによってDaily midnight buildWeekly Sunday buildトリガーされた場合にのみ実行されます。

stages:
- stage: stage1
  # Run this stage only when the pipeline is triggered by the 
  # "Daily midnight build" cron schedule
  condition: eq(variables['Build.CronSchedule.DisplayName'], 'Daily midnight build')
  jobs:
  - job: job1
    steps:
    - script: echo Hello from Stage 1 Job 1

- stage: stage2
  dependsOn: [] # Indicate this stage does not depend on the previous stage
  jobs:
  - job: job2
    steps:
    - script: echo Hello from Stage 2 Job 2
  - job: job3 
    # Run this job only when the pipeline is triggered by the 
    # "Weekly Sunday build" cron schedule
    condition: eq(variables['Build.CronSchedule.DisplayName'], 'Weekly Sunday build')
    steps:
    - script: echo Hello from Stage 2 Job 3

関連項目