パイプラインの開始条件
これらのオプションによって、パイプラインの開始条件を制御できます。パイプラインの開始を特定の条件に制限すると (プル リクエストが作成またはアップデートされた場合のみなど)、チームが使用するビルド時間数を削減できます。
パイプラインは、次のようなさまざまな条件下で開始するように設定できます。
コミットが任意のブランチにプッシュされたときに実行する — 既定の開始条件。
コミットが指定されたブランチにプッシュされたときに実行する — ブランチ開始条件。
プル リクエストが作成またはアップデートされ、指定されたブランチをターゲットにしたときに実行する — プル リクエスト開始条件。
Run when a Git tag is created — The Tags start condition.
ユーザーにより手動で開始されたときに実行する — カスタム開始条件。
パイプラインの開始条件
Pipelines は、次のオプションを使用して条件付きで開始するように設定できます。
Pipelines プロパティ
pipelines プロパティは、リポジトリのビルド プロセスを定義するために使用されます。パイプラインの開始条件とパイプラインのステップが含まれます。pipelines プロパティは必須で、リポジトリごとに 1 回のみ定義する必要があります。
プロパティ — pipelines
必須 — はい
Data type — Block (YAML spec - Block Mapping)
指定可能な親プロパティ — YAML ルート (pipelines は必ず最上位のプロパティとなります)
Allowed child properties — Requires one or more of the default, branches, pull-requests, tags, and custom properties.
例 — pipelines プロパティを使用して、基本的なパイプラインを作成する
pipelines:
default:
- step:
name: Hello world example
script:
- echo "Hello, World!"既定
他のセクションのパイプライン定義に一致しないすべてのブランチのパイプライン定義が含まれます。
ブランチ固有のパイプラインが定義されている場合を除き、既定のパイプラインはリポジトリへのプッシュ (タグ プッシュは除く) のたびに実行されます。ブランチ パイプラインは branch セクションで定義できます。
コミットをプッシュしてパイプラインのトリガーをスキップしたい場合は、[skip ci] または [ci skip] をコミット メッセージに追加できます。
プロパティ — default
必須 — いいえ
Data type — List of step, stage, or parallel properties (YAML spec - Sequence)
Allowed parent properties — pipelines
Allowed child properties — Requires one or more of the step, stage, or parallel properties.
例 — default プロパティを使用して、基本的なパイプラインを定義する
pipelines:
default:
- step:
name: Hello world example
script:
- echo "Hello, World!"例 — branches プロパティと default プロパティを併用する
次の例は、既定のパイプラインを定義し、hotfix/ がプレフィックス付けされたブランチにプッシュされた変更がないときに実行する方法を示しています。
pipelines:
branches:
hotfix/*:
- step:
name: Build hotfix branch
script:
- echo "Hello, hotfix!"
default:
- step:
name: All other builds
script:
- echo "Hello, World!"ブランチ
Defines all branch-specific build pipelines. The names or expressions in this section are matched against branches in your Git repository. Glob patterns can be used for matching branches. For information on using glob patterns to match branch names, see Use glob patterns on the Pipelines yaml file.
コミットをプッシュしてパイプラインのトリガーをスキップしたい場合は、[skip ci] または [ci skip] をコミット メッセージに追加できます。
プロパティ — branches
必須 — いいえ
Data type — Block of new-line separated name-value pairs (YAML spec - Block Mapping)
Allowed parent properties — pipelines
Allowed child properties — User-defined glob patterns matching possible branch names, with step, stage, or parallel elements nested within
例 — branches プロパティを使用して、ブランチベースのパイプラインを定義する
リポジトリには、その bitbucket-pipelines.yml に次の Bitbucket Pipelines 構成があります。
image: node:lts
pipelines:
default:
- step:
script:
- echo "This script runs on all branches that don't have any specific pipeline assigned in 'branches'."
branches:
main:
- step:
script:
- echo "This script runs only on commit to the main branch."
feature/*:
- step:
image: openjdk:8 # This step uses its own image
script:
- echo "This script runs only on commit to branches with names that match the feature/* pattern."main ブランチに基づく次の 2 つのブランチがリポジトリにプッシュされた場合
feature/BB-123-fix-links— 機能開発ブランチexperimental— 実験的または革新的な変更を含むブランチ
各ブランチのルート ディレクトリに同じ bitbucket-pipelines.yml ファイルがあります。ブランチにプッシュするたびに、Pipelines では bitbucket-pipelines.yml ファイルでブランチに割り当てられたスクリプトが実行されます。このファイルでは、
mainブランチ パイプライン定義に、コミットがmainブランチにプッシュまたはマージされたときに実行する手順が含まれています。feature/*ブランチ定義に、feature/BB-123-fix-linksブランチなど、feature/がプレフィックス付けされた任意のブランチにコミットがプッシュされたときに実行する手順が含まれています。defaultパイプライン定義に、experimentalブランチなど、mainではなく、feature/がプレフィックス付けされていない任意のブランチへのコミット時に実行する手順が含まれています。
プル リクエスト
pull-requests プロパティは、プル リクエストが作成されたときのみ実行するパイプラインを定義します。実行前に宛先ブランチを作業ブランチにマージします。フォークされたリポジトリからのプル リクエストは、パイプラインをトリガーしません。マージが失敗すると、パイプラインが停止します。注意: 割り当てられたブランチは、プル リクエストのソース ブランチである必要があります。
プル リクエスト パイプラインは定義されている任意のブランチおよびデフォルト パイプラインに加えて実行されるため、定義が重複すると 2 つのパイプラインが同時に実行される場合があります。
If you already have branches in your configuration, and you want them all to only run on pull requests, replace the keyword branches with pull-requests. Glob patterns can be used for matching branch names. For information on using glob patterns to match branch names, see Use glob patterns on the Pipelines yaml file.
コミットをプッシュしてパイプラインのトリガーをスキップしたい場合は、[skip ci] または [ci skip] をコミット メッセージに追加できます。
プロパティ — pull-requests
必須 — いいえ
Data type — Block of new-line separated name-value pairs (YAML spec - Block Mapping)
Allowed parent properties — pipelines
Allowed child properties — User-defined glob patterns matching possible branch names, with step, stage, or parallel elements nested within
例 — pull-requests プロパティを使用して、プル リクエストが作成されたときにパイプラインを実行する
pipelines:
pull-requests:
feature/*:
- step:
name: Build for feature branch pull request
script:
- echo "Hello, feature branch PR!"
hotfix/*:
- step:
name: Build for hotfix branch pull request
script:
- echo "Hello, hotfix PR!"
'**':
- step:
name: Build for all other pull requests
script:
- echo "Hello, non-feature, non-hotfix pull request!"例 — pull-requests および default プロパティを使用して、プル リクエストベースのパイプラインと既定のパイプラインを定義する
次のパイプラインはどちらも、ブランチに hotfix/ がプレフィックス付けされている場合に実行されることにご注意ください。既定のパイプラインは任意のブランチ (hotfix/ がプレフィックス付けされたブランチを含む) がリポジトリにプッシュされたときに開始され、プル リクエスト パイプラインはブランチを照合するためにプル リクエストが作成されたときに開始されます。
pipelines:
pull-requests:
hotfix/*:
- step:
name: Build for hotfix branch pull request
script:
- echo "Hello, hotfix PR!"
default:
- step:
name: All other builds
script:
- echo "Hello, World!"Tags
すべてのタグ固有のビルド パイプラインを定義します。このセクションの名前または表現は、Git リポジトリのタグや注釈付きタグと照合されます。glob パターンはタグの照合に使用できます。
For information on using glob patterns to match branch names, see Use glob patterns on the Pipelines yaml file.
プロパティ — tags
必須 — いいえ
Data type — Block of new-line separated name-value pairs (YAML spec - Block Mapping)
Allowed parent properties — pipelines
Allowed child properties — User-defined glob patterns matching possible git tags, with step, stage, or parallel elements nested within
例 — tags プロパティを使用して、タグベースのパイプラインを定義する
pipelines:
tags:
'*-windows':
- step:
name: Build for *-windows tags
script:
- echo "Hello, Windows!"
'*-macos':
- step:
name: Build for *-macos tags
script:
- echo "Hello, macOS!"
'*-linux':
- step:
name: Build for *-linux tags
script:
- echo "Hello, Linux!"例 — tags および default プロパティを使用して、タグベースのパイプラインと既定のパイプラインを定義する
pipelines:
tags:
'*-windows':
- step:
name: Build for *-windows tags
script:
- echo "Hello, Windows!"
'*-macos':
- step:
name: Build for *-macos tags
script:
- echo "Hello, macOS!"
'*-linux':
- step:
name: Build for *-linux tags
script:
- echo "Hello, Linux!"
default:
- step:
name: Build for all other branches and commits
script:
- echo "Hello, branch or commit!"カスタム (手動) パイプライン
The custom property is used to define pipelines that can only be triggered manually, or scheduled from the Bitbucket Cloud interface. For details on creating manual or scheduled pipelines, see Create manual and scheduled pipelines.
プロパティ — custom
必須 — いいえ
Data type — Block of new-line separated name-value pairs (YAML spec - Block Mapping)
Allowed parent properties — pipelines
Allowed child properties — User-defined string which will be used as the name of the manual pipeline, with step, stage, parallel, or variables elements nested within
例 — custom プロパティを使用して、手動パイプライン「sonar」を定義する
pipelines:
custom: # Pipelines that are triggered manually
sonar: # The name that is displayed in the list in the Bitbucket Cloud GUI
- step:
script:
- echo "Manual triggers for Sonar are awesome!"例 — custom プロパティを使用して、2 つの手動パイプラインと 1 つの自動パイプラインを定義する
pipelines:
custom: # Pipelines that are triggered manually
sonar: # The name that is displayed in the list in the Bitbucket Cloud GUI
- step:
script:
- echo "Manual triggers for Sonar are awesome!"
deployment-to-prod: # Another display name
- step:
script:
- echo "Manual triggers for deployments are awesome!"
branches: # Pipelines that run automatically on a commit to a branch
staging:
- step:
script:
- echo "Auto pipelines are cool too."カスタム (手動) パイプライン変数
実行時に設定されるカスタム パイプライン変数は、custom パイプラインでのみ使用可能です。
Custom pipeline variables allows the defined variables to be set or updated when a custom pipeline is run. Each variable must have a name. Variables can also have a default value and a list of allowed-values. For details on creating manual or scheduled pipelines, see Create manual and scheduled pipelines.
Secrets and login credentials should be stored as user-defined pipeline variables to avoid being leaked. For details, see Variables and secrets — User-defined variables.
プロパティ — variables
必須 — いいえ
Data type — A list of key-value pairs (YAML spec - Block Mapping)
Allowed parent properties — A manual pipeline name, nested in a custom property
指定可能な子プロパティ — name、default、allowed-values、description
プロパティ | 必須またはオプション | 説明 | データ タイプ |
|---|---|---|---|
| 必須 | 変数の名前。 | 文字列 |
| 任意 | The default value for the variable. If the variable is not manually set when the pipeline is run, then this value will be used. To define variables that can’t be set at runtime, use User-defined variables. | 文字列 |
| 任意 | 変数に指定可能な値のリスト。 | List of Strings (YAML spec - Sequence) |
| 任意 | ユーザーがプロパティにどのような値を追加すべきかを知るのに役立つ具体的な情報や簡単な要約を提供します。 | 文字列 |
例 — variables プロパティを使用して、カスタム パイプライン変数を定義する
pipelines:
custom: # Pipelines that are triggered manually
us-build: # The name that is displayed in the list in the Bitbucket Cloud GUI
- variables:
- name: Username
- name: Role
default: "admin" # optionally provide a default variable value
description: "Add user role"
- name: Region
default: "us-east-1"
allowed-values: # optionally restrict variable values
- "ap-southeast-2"
- "us-east-1"
- "us-west-2"
- step:
script:
- echo "$Username manually triggered for a build for $Region as $Role!"
トリガー プロパティ
triggers プロパティを使用すると、1 つのイベントから複数のパイプラインを並行してトリガーできる条件ベースのルールを定義できます。ブランチ、タグ、またはプル リクエストを使用して単一のパイプラインを選択する従来のセレクター ベースのアプローチとは異なり、トリガーは論理式を使用して実行するパイプラインを決定するため、より柔軟で強力な構成が可能になります。
トリガー プロパティを使用すると、次のことが可能になります。
単一のイベントから独立してパイプラインを並列に実行する
論理式を使用して複雑な条件を設定する
単一のイベントから複数のパイプラインをトリガーする
大規模でモノリシックなパイプラインを、焦点を絞った小さなパイプラインに分離する
プロパティ — triggers
必須 — いいえ
Data type — Block (YAML spec - Block Mapping)
指定可能な親プロパティ — YAML ルート (triggers は必ず最上位のプロパティとなります)
Allowed child properties — Trigger type, with a list of condition definitions nested within.
例 — トリガー プロパティを使用して、「main」ブランチがプッシュされたときに 2 つのパイプラインが実行されるように構成します。
triggers:
repository-push:
- condition: BITBUCKET_BRANCH == "main"
pipelines:
- pipeline1
- pipeline2この例では、コミットが main ブランチにプッシュされるときに pipeline1 と pipeline2 の両方を並行して実行します。
例 — triggers プロパティを使用して、「main」ブランチでプル リクエストが作成またはアップデートされたときに 2 つのパイプラインが実行されるように構成します。
triggers:
pullrequest-push:
- condition: BITBUCKET_BRANCH == "main"
pipelines:
- pipeline1
- pipeline2この例では、main ブランチを含むプル リクエストが作成または更新されたときに、両方のパイプラインを実行します。
トリガーのタイプ
トリガー タイプは、Bitbucket に関連条件を評価させるリポジトリ イベント (プッシュまたはプル リクエストのアップデートなど) を指定します。条件が true と評価されると、指定されたパイプラインが実行されます。
サポートされるトリガー タイプ。
repository-push
コミットが任意のブランチにプッシュされたとき、または git tag が作成されたときに評価されます。pullrequest-push
プル リクエストが作成またはアップデートされたときに評価されます。
今後のリリースでは、その他のトリガー タイプがサポートされる可能性があります。
必須 — いいえ
データ タイプ — 文字列
指定可能な値 — repository-push、pullrequest-push
指定可能な親プロパティ — triggers
指定可能な子プロパティ — condition、pipelines
条件
condition プロパティは、指定されたパイプラインをトリガーする必要があるかどうかを判断するために実行時に評価される論理式を定義します。条件ではパイプライン変数を使用でき、論理演算子により柔軟な一致をサポートします。
プロパティ — condition
必須 — はい
データ タイプ — 文字列
指定可能な親プロパティ — triggers 内でトリガー タイプの下にネストされる必要があります。
指定可能な子プロパティ — なし
例 – プル リクエストが作成またはアップデートされたときにパイプラインをトリガーします。ソース ブランチは「feature/test」、宛先ブランチは「main」です。
pipelines:
custom:
pipeline1:
- step:
name: Test
script:
- echo "Hello, World!"
triggers:
pullrequest-push:
- condition: BITBUCKET_BRANCH == "feature/test" && BITBUCKET_PR_DESTINATION_BRANCH == "main"
pipelines:
- pipeline1この例では、プル リクエストが feature/test ブランチから main ブランチに作成または更新された場合にのみ pipeline1 がトリガーされます。
Pipelines
pipelines プロパティは、関連付けられた条件が true と評価されたときにトリガーされるパイプラインを指定します。リストされているすべてのパイプラインは並列に開始されます。
Note: Only pipelines defined in the custom section of your YAML file can be referenced in triggers. Make sure each pipeline name in this list matches a custom pipeline you have defined. Read about custom pipelines
プロパティ — pipelines
必須 — はい
Data type — List of Strings (YAML spec - Sequence)
指定可能な親プロパティ - triggers のトリガー タイプ内の条件の下にネストされる必要があります
指定可能な子プロパティ — なし
例 – コミットが「main」ブランチにプッシュされたときに 2 つのパイプラインを並行してトリガーします。
pipelines:
custom:
pipeline1:
- step:
name: Test
script:
- echo "Hello, World!"
pipeline2:
- step:
name: Test
script:
- echo "Hello, World!"
triggers:
repository-push:
- condition: BITBUCKET_BRANCH == "main"
pipelines:
- pipeline1
- pipeline2この例では、コミットが main ブランチにプッシュされるときに pipeline1 と pipeline2 の両方を並行して実行します。
トリガー条件の記述
トリガー条件は、論理式を使用して、特定のイベントに対してどのパイプラインを実行するかを決定します。各条件は、使用可能なパイプライン変数を使用して実行時に評価されます。条件が true と評価されると、関連するパイプラインが実行されます。
条件式では、次の変数を使用できます。
BITBUCKET_BRANCHE — イベントのブランチの名前。
BITBUCKET_TAG — イベントのタグの名前。
BITBUCKET_PR_DESTINATION_BRANCH — プル リクエストの宛先ブランチ。
BITBUCKET_PR_DESTINATION_COMMIT — プル リクエストの宛先のコミット ハッシュ。
BITBUCKET_PR_ID — プル リクエストの ID。
すべての非セキュア ワークスペース変数とリポジトリ変数
ガイドライン:
条件式では変数は引用符なしで表記する必要があります (例:
BITBUCKET_BRANCH)。文字列リテラルは引用符で囲む必要があります (例:
"main")。ブール値と数値がサポートされており、引用符なしで表記されます。
すべての比較では大文字と小文字が区別されます。
変数は大文字と小文字を区別し、このように使用する必要があります。
サポートされる演算子:
==— 等式!=— 不等式&&— 論理 AND||— 論理 OR!— 論理 NOT()— グループ化>,>=,<,<=— 比較演算子glob(value, pattern)— glob 構文を使用したパターン マッチング
例:
単純等式:
condition: BITBUCKET_BRANCH == "main"
ブランチが「main」と一致するときに実行されます。Glob パターン マッチング:
condition: glob(BITBUCKET_BRANCH, "feature/*")
「feature/」で始まる任意のブランチに対して実行されます。複雑な論理式:
condition: BITBUCKET_BRANCH == "main" && BITBUCKET_PR_DESTINATION_BRANCH == "production"
ブランチが「main」で PR の宛先が「production」の場合に実行されます。OR の使用:
condition: BITBUCKET_BRANCH == "integration" || BITBUCKET_PR_DESTINATION_BRANCH == "main"
ブランチが「integration」、または PR の宛先が「main」の場合に実行されます。NOT の使用:
condition: !(glob(BITBUCKET_BRANCH, "feature/*") || BITBUCKET_BRANCH == "main")
「main」ではなく、「feature/*」と一致しないブランチに対して実行されます。
glob() 関数
glob() 関数により、トリガー条件での柔軟なパターン マッチングが可能になり、ワイルドカードと中括弧の展開を使用して、ブランチ、タグ、またはその他の変数を一致させることができます。値がパターンと一致する場合は true を返し、それ以外の場合は false を返します。
構文とパラメーター
構文: glob(value, "pattern")
value: テストする変数 (例えば、
BITBUCKET_BRANCH、BITBUCKET_TAG)pattern: 一致する glob パターン (引用符で囲む必要があります。
*、?、などのワイルドカードおよび、{}などの中括弧拡張をサポートします。パターンでは大文字と小文字が区別されます)
動作
The glob() function follows the same pattern-matching rules as using glob patterns on the Pipelines yaml file.
条件式では glob() と論理演算子 (&&、||、!) を組み合わせて高度な一致を行うことができます。
例:
フィーチャー ブランチとの一致:
glob(BITBUCKET_BRANCH, "feature/*")
「feature/」で始まるすべてのブランチに一致します。バージョン タグとの一致:
glob(BITBUCKET_TAG, "v1.*")
「v1.0」、「v1.1」などのタグに一致します中括弧拡張を使用した複数パターンとの一致:
glob(BITBUCKET_BRANCH, "{main,develop,staging}")
ブランチが「main」、「develop」、「staging」のいずれかである場合に一致します 。glob ** によるすべてとの一致:
glob(BITBUCKET_BRANCH, "**")
任意のブランチ名と一致します。
トリガーと従来のセレクターとの違い
アスペクト | 従来のセレクター (ブランチ、タグなど) | トリガー |
|---|---|---|
一致の動作 | 最初に一致したパイプラインのみが実行される | 一致したパイプラインはすべて並行して実行される |
複数のパイプライン | イベントごとに実行できるパイプラインは 1 つだけ | イベントごとに複数のパイプラインを実行可能 |
条件の複雑さ | 基本的なパターン マッチング | 論理式と高度なパターン マッチング (glob、AND/OR/NOT) |
重要: トリガーは従来のセレクターと累積されます。従来のセレクターとトリガーの両方が一致すると、両方のパイプラインが実行されます。
トリガーの制限事項
トリガーには次の制限が適用されます。
YAML ファイルあたりトリガー タイプ 1 つにつき最大 20 条件 (たとえば、
repository-pushにつき最大 20、pullrequest-pushにつき最大 20)。1 つのイベントから最大 100 のパイプラインを (一致するすべての条件とトリガー タイプにわたって) トリガーできます。
All pipelines referenced in triggers must be defined in the custom section of your YAML file.
Imported pipelines are supported (e.g., pipelines included via YAML imports), but they must still be defined in the custom pipelines.)
この内容はお役に立ちましたか?