ステージ オプション
ステージを使用すると、パイプライン ステップを共有プロパティで論理的にグループ化できます。たとえば、同じデプロイ環境のステップをグループ化したり、デプロイ環境を複数のステップでロックしたり (他のパイプラインがそれと相互作用しないようにするため)、複数の連続したステップでデプロイ変数を共有したりできます。
概要
ステージをセットアップする
パイプラインにステージを追加するには、stage
プロパティを追加し、そのステージ内に 1 つ以上のステップをグループ化します。次に例を示します。
pipelines:
default:
- stage:
name: Build and test
steps:
- step:
name: Build app
script:
- sh ./build-app.sh
- step:
name: Run unit tests
script:
- sh ./run-tests.sh
デプロイにステージを使用する
デプロイ ステージを使用すると、次のことが可能になります。
ステップを組み合わせて論理的に構造化されたデプロイを形成する。
デプロイのどの部分が失敗したかを簡単に確認する。
完全な再デプロイを実行するのではなく、デプロイの失敗した部分のみを再実行する。
同じステージ内の複数のステップにわたってデプロイ変数を共有します。
同じステージで複数のステップにわたってデプロイ環境をロックします。
また、デプロイ ステージは、デプロイ権限と同時実行制御による恩恵も受けます。
デプロイ ステージを作成するには、次の手順に従います。
パイプラインに
stage
を追加します。ステージに
deployment
プロパティを追加します。ステージに適切な
steps
を追加します。
例:
pipelines:
default:
- step:
name: Build and test
script:
- sh ./build-app.sh
- stage:
name: Deploy to staging
deployment: staging
steps:
- step:
name: Deploy
script:
- sh ./deploy-app.sh
- step:
name: Run end-to-end tests
script:
- sh ./run-e2e-tests.sh
このデプロイ ステージは次の 2 つのステップで構成されています。
最初のステップでは、アプリをステージング環境にデプロイします。
2 つ目のステップでは、ステージング環境に対してエンドツーエンドのテストを実行し、デプロイによって問題が発生しなかったことを確認します。
Use Stages for environments
Using environments on stages allows you to:
Set the same environment on all steps within the stage (with all permissions on the environment applied as configured).
Share Deployment Environment Variables over multiple steps within the same stage.
To configure environments on a stage:
パイプラインに
stage
を追加します。ステージに
environment
プロパティを追加します。ステージに適切な
steps
を追加します。
例:
pipelines:
default:
- step:
name: Build and test
script:
- sh ./build-app.sh
- stage:
name: Steps using staging environment
environment: staging
steps:
- step:
name: Run end-to-end tests slice 1
script:
- sh ./run-e2e-tests.sh
- step:
name: Run end-to-end tests slice 2
script:
- sh ./run-e2e-tests.sh
未完了のデプロイ ステージを再実行する
デプロイ ステージ内で失敗、一時停止、または停止したステップを再実行することは、ステップを再実行することと似ています。ただし、追加で次のような条件があります。
パイプライン アーティファクトがまだ使用可能である必要があります (有効期限が切れていないこと)。
ステージ内のステップを再実行できるのは、同じ環境で新しいデプロイや今後のデプロイがない場合のみです。
デプロイ ステージを再デプロイする
以前に成功したデプロイ ステージを再デプロイするには、次の手順に従います。
パイプライン アーティファクトがまだ使用可能であること (有効期限が切れていないこと) を確認します。
デプロイ ステージ全体を再実行します。
デプロイ ステージの未完了の再デプロイを再実行する
デプロイ ステージ内で失敗または停止したステップを再実行するには、次の手順に従います。
パイプライン アーティファクトがまだ使用可能である必要があります (有効期限が切れていないこと)。
ステージ内のステップを再実行できるのは、同じ環境で新しいデプロイや今後のデプロイがない場合のみです。ステージは最初のステップから再デプロイできます。
制限事項
ステージに含めることができるステップの最大数は次のとおりです。
Free プランのワークスペースの場合は 10 ステップ
Standard または Premium プランのワークスペースの場合は 100 ステップ
並行ステージはサポートされていません。
ステージには並行ステップを含めることはできません。
ステージには手動でトリガーされるステップを含めることはできませんが、ステージを手動でトリガーするように設定することは可能です。
ステージには条件付きステップを含めることはできませんが、ステージを条件付きとして設定することは可能です。
ステージ内でのアーティファクト ダウンロードの無効化はサポートされていません。
ステップではステージに設定されているプロパティを上書きすることはできません。
部分的に完了したデプロイ ステージは、それ以降に同じ環境に別の変更がデプロイされた場合は続行できなくなります。
ステージ オプション
次のオプションはステージを設定するために使用できます。
段階
ステージを使用すると、共有プロパティを持つパイプライン ステップをグループ化できます。たとえば、ステージを使用して、デプロイに必要なステップ (アプリのデプロイやデプロイの成否の確認など) をグループ化できます。
パイプライン ステージの作成と使用については、「ステージ」を参照してください。
プロパティ — stage
必須 — いいえ
データ タイプ — 改行で区切られたキーと値のペアのブロック (YAML 仕様 - ブロック マッピング)
指定可能な親プロパティ — default、branches、pull-requests、tags、custom
Allowed child properties — steps (required), name, deployment, environment, trigger, condition, and on-fail
例 — stage を使用して、パイプライン ステップをグループ化する
pipelines:
default:
- stage:
name: Build and test
steps:
- step:
name: Build app
script:
- sh ./build-app.sh
- step:
name: Run unit tests
script:
- sh ./run-tests.sh
手順
steps
プロパティには、stage
または parallel
の step
のリストが含まれます。ステップ リストには少なくとも 1 つの step
が必要です。
プロパティ — steps
必須 — はい
データ タイプ — 改行で区切られたキーと値のペアのブロック (YAML 仕様 - ブロック マッピング)
指定可能な親プロパティ — parallel と stage
指定可能な子プロパティ — step (必須)
例 — step プロパティを使用して、並行グループのステップをリストする
pipelines:
default:
- step: # sequential step
name: Build
script:
- ./build.sh
- step: # sequential step
name: Build
script:
- ./build.sh
- parallel: # these 2 steps will run in parallel
steps:
- step:
name: Integration 1
script:
- ./integration-tests.sh --batch 1
- step:
name: Integration 2
script:
- ./integration-tests.sh --batch 2
- step: # non-parallel step
script:
- ./deploy.sh
例 — step プロパティを使用して、ステージのステップをリストする
pipelines:
default:
- stage:
name: Build and test
steps:
- step:
name: Build app
script:
- sh ./build-app.sh
- step:
name: Run unit tests
script:
- sh ./run-tests.sh
条件
The Use
The file match pattern specified in the 考慮される変更内容In a その他のタイプのパイプラインでは最後のコミットのみが考慮されます。複数のコミットを同時にブランチにプッシュしたり、特定のブランチに複数回プッシュしたりすると、失敗している プロパティ — 必須 — いいえ データ タイプ — 改行で区切られたキーと値のペアのブロック (YAML 仕様 - ブロック マッピング) 指定可能な子プロパティ — changesets (必須) 例 — condition オプションを使用して、特定のファイルの変更時のみにステップを実行するpipelines:
default:
- step:
name: step1
script:
- echo "failing paths"
- exit 1
condition:
changesets:
includePaths:
# only xml files directly under path1 directory
- "path1/*.xml"
# any changes in deeply nested directories under path2
- "path2/**" 例 — condition オプションを使用して、特定のファイルの変更時のみにステージを実行するpipelines:
default:
- stage:
name: Build and test
condition:
changesets:
includePaths:
# only xml files directly under path1 directory
- "path1/*.xml"
# any changes in deeply nested directories under path2
- "path2/**"
steps:
- step:
name: Build app
script:
- sh ./build-app.sh
- step:
name: Run unit tests
script:
- sh ./run-tests.sh |
changesets
条件チェンジセットThe プロパティ — 必須 — condition オプションを使用する場合は必須です。 データ タイプ — 改行で区切られたキーと値のペアのブロック (YAML 仕様 - ブロック マッピング) 指定可能な親プロパティ — condition Allowed child properties — either includePaths or excludePaths (required) 例 — condition オプションを使用して、特定のファイルの変更時のみにステップを実行するpipelines:
default:
- step:
name: step1
script:
- echo "failing paths"
- exit 1
condition:
changesets:
includePaths:
# only xml files directly under path1 directory
- "path1/*.xml"
# any changes in deeply nested directories under path2
- "path2/**" 例 — condition オプションを使用して、特定のファイルの変更時のみにステージを実行するpipelines:
default:
- stage:
name: Build and test
condition:
changesets:
includePaths:
# only xml files directly under path1 directory
- "path1/*.xml"
# any changes in deeply nested directories under path2
- "path2/**"
steps:
- step:
name: Build app
script:
- sh ./build-app.sh
- step:
name: Run unit tests
script:
- sh ./run-tests.sh |
includePaths
condition
および changesets
オプションと一緒に使用すると、includePaths
オプションによって、変更を確認するためのファイルまたはディレクトリのリストを提供できます。リスト内のファイルがコミットによって変更されている場合は step
または stage
が実行され、それ以外の場合はステップがスキップされます。
プロパティ — includePaths
必須 — いいえ
データ タイプ — パスのリスト (glob パターンを指定可能) (YAML 仕様 - シーケンス)
指定可能な親プロパティ — changesets
例 — condition オプションを使用して、特定のファイルの変更時のみにステップを実行する
pipelines:
default:
- step:
name: step1
script:
- echo "failing paths"
- exit 1
condition:
changesets:
includePaths:
# only xml files directly under path1 directory
- "path1/*.xml"
# any changes in deeply nested directories under path2
- "path2/**"
例 — condition オプションを使用して、特定のファイルの変更時のみにステージを実行する
pipelines:
default:
- stage:
name: Build and test
condition:
changesets:
includePaths:
# only xml files directly under path1 directory
- "path1/*.xml"
# any changes in deeply nested directories under path2
- "path2/**"
steps:
- step:
name: Build app
script:
- sh ./build-app.sh
- step:
name: Run unit tests
script:
- sh ./run-tests.sh
excludePaths
When used with the プロパティ — 必須 — いいえ データ タイプ — パスのリスト (glob パターンを指定可能) (YAML 仕様 - シーケンス) 指定可能な親プロパティ — changesets Example — using the condition option to skip a step when certain files changepipelines:
default:
- step:
name: step1
script:
- echo "failing paths"
- exit 1
condition:
changesets:
excludePaths:
# only xml files directly under path1 directory
- "path1/*.xml"
# any changes in deeply nested directories under path2
- "path2/**" Example — using the condition option to skip a stage when certain files changepipelines:
default:
- stage:
name: Build and test
condition:
changesets:
excludePaths:
# only xml files directly under path1 directory
- "path1/*.xml"
# any changes in deeply nested directories under path2
- "path2/**"
steps:
- step:
name: Build app
script:
- sh ./build-app.sh
- step:
name: Run unit tests
script:
- sh ./run-tests.sh |
デプロイメント
Deployment の stage
または step
の環境を設定し、Deployment ダッシュボードを整理するために使用されます。Deployment ステージに属するすべてのステップが Deployment ステップになります。既定の環境: test
、staging
、または production
。step
または stage
のデプロイ環境を設定するには、環境名を含めます。
詳細情報
デプロイ ステージについては「デプロイ ステージ」をご確認ください。
デプロイ環境の作成と設定については「デプロイのセットアップと監視」をご確認ください。
プロパティ — deployment
必須 — いいえ
データ タイプ — 文字列
指定可能な値 — デプロイ環境の名前
例 — deployment を使用して、ステップのデプロイ環境を設定する
pipelines:
default:
- step:
name: Deploy to production
deployment: production env 1
script:
- python deploy.py prod_env_1
例 — deployment を使用して、ステージのデプロイ環境を設定する
pipelines:
default:
- stage:
name: Build and test
deployment: staging
steps:
- step:
name: Build app
script:
- sh ./build-app.sh
- step:
name: Run unit tests
script:
- sh ./run-tests.sh
- stage:
name: Deploy to Production
deployment: prod
trigger: manual
steps:
- step:
name: Build app
script:
- sh ./build-app.sh
- step:
name: Run unit tests
script:
- sh ./run-tests.sh
環境
Sets the environment for a step or stage. This allows steps using that environment to access the environment variables, given the branch and admin permissions' checks pass.
If specified on a stage, all steps within that stage will be assigned the same environment.
To set the environment of a step
or stage
, include the Environment name.
詳細情報
Environment stages, see Environment stages.
To create and configure environments, see Set up and monitor deployments.
プロパティ — environment
必須 — いいえ
データ タイプ — 文字列
Allowed values — The name of an Environment
Example — using environment to set the environment for a step
pipelines:
default:
- step:
name: Deploy to production
environment: production env 1
script:
- python deploy.py prod_env_1
Example — using environment to set the environment for stages
pipelines:
default:
- stage:
name: Build and test for staging
environment: staging
steps:
- step:
name: Build app
script:
- sh ./build-app.sh
- step:
name: Run unit tests
script:
- sh ./run-tests.sh
- stage:
name: Build and test for production
environment: prod
steps:
- step:
name: Build app
script:
- sh ./build-app.sh
- step:
name: Run unit tests
script:
- sh ./run-tests.sh
名前
step
または stage
の名前。名前は、Bitbucket Pipelines のログと Bitbucket UI に表示されます。名前は (パイプライン内で) 一意であり、ステージ内のステップを説明するものでなければなりません。
プロパティ — name
必須 — いいえ
データ タイプ — 文字列
例 - name を使用して 1 つのステージと 2 つのステップにラベルを付ける
pipelines:
default:
- stage:
name: Build and test
steps:
- step:
name: Build app
script:
- sh ./build-app.sh
- step:
name: Run unit tests
script:
- sh ./run-tests.sh
- step:
script:
- pipe: atlassian/slack-notify:latest
variables:
WEBHOOK_URL: $SLACK_WEBHOOK
PRETEXT: 'Hello, Slack!'
MESSAGE: 'Hello, Slack!!'
トリガー
ステージを自動的に実行する (既定の動作) か、Bitbucket ユーザー インターフェイスでユーザーが手動でトリガーした場合にのみ実行するように設定します。パイプライン内の最初のステージは手動にはできません。パイプライン全体を手動で実行するように設定するには、カスタム パイプライン トリガーを使用します。以下は、手動のステップとステージの特徴です。
最初の
step
またはstage
にはできません。設定されている順序でのみ実行できます。手動の
step
またはstage
はスキップできません。前の
step
またはstage
が正常に完了した場合のみ実行できます。リポジトリへの書き込みアクセス権限を持つユーザーのみがトリガーできます。
Pipelines の Web インターフェイス経由でトリガーされます。
ビルドが手動ステップとアーティファクトの両方を使用している場合、アーティファクトはそれらのアーティファクトを生成したステップの実行後 14 日間保存されます。この期間が過ぎると、アーティファクトは期限切れとなり、パイプラインでは以降のあらゆる手動ステップと手動ステージを実行できなくなります。
プロパティ — trigger
必須 — いいえ
データ タイプ — 文字列
指定可能な値 — automatic
および manual
既定値 — automatic
例 — trigger を使用して、ステップを手動に設定する
pipelines:
default:
- step:
name: Build
script:
- npm run build
artifacts:
- dist/**
- step:
name: Deploy
trigger: manual
script:
- ./deploy.sh
例 — trigger を使用してステージを手動に設定する
pipelines:
default:
- stage:
name: Linting
steps:
- step:
script:
- sh ./run-linter.sh
- stage:
name: Build and test
trigger: manual
steps:
- step:
name: Build app
script:
- sh ./build-app.sh
- step:
name: Run unit tests
script:
- sh ./run-tests.sh
この内容はお役に立ちましたか?