Bitbucket is getting a new navigation

We’re rolling out these changes, so the documentation may not match your experience in the Bitbucket Cloud app. Read about the new Bitbucket navigation

デプロイを設定、監視する

デプロイを設定する

This guide covers the general setup of deployment environments. If you’re seeking platform-specific information, check out the deployment guides.

まず、Bitbucket 設定で環境が定義されます。

以下を設定することができます。

  • 名前

  • 環境のタイプ

  • ダッシュボードでの表示順

  • その環境に固有の任意の変数

  • Premium プランの場合は、それぞれにデプロイするユーザー

次に、bitbucket-pipelines.yml ファイルでそれらを参照して、デプロイメント ダッシュボードに表示します。

ステップ 1: 環境を定義する

まずに、環境の詳細情報が追加されます。

パイプラインを有効にすると、"Test" と呼ばれるテスト環境、"Staging" と呼ばれるステージング環境、および "Production" と呼ばれる本番環境の 3 つの基本的な環境が既定で作成されます。

環境のタイプは一般に、環境を論理的に並べるために使用されます。そのため、使用する機能と一致していない場合も問題ありません。

  • リポジトリで、左側のサイドバーにある [リポジトリ設定] を選択します。

  • [Pipelines] セクションで、[デプロイ] を選択します。

  • 任意の環境を選択して次の操作を行います。

    • 名前を変更

    • 環境に固有のデプロイメント変数を設定

      デプロイ変数はチーム変数とリポジトリ変数の両方を上書きします。また、同じ名前の変数を各デプロイ環境に対して別ので設定できます。たとえば、環境ごとに異なる $DEPLOYMENT_SECRET_KEY を設定できます。その後に、管理者のみがシークレット キーを使用できるように環境を制限することもできます。

    • デプロイ機能を管理者、または特定のブランチに制限します。注意: これは Premium 機能のため、Premium のカスタマーのみが利用できます

If you want to add more environments, decide which type of environment best describes it (test, staging, or production) and select add environment in that section.

You can also move environments within their type by selecting the left hand edge and dragging.

ステップ 2: デプロイ手順を構成する

Add the deployment keyword to the step or stage, followed by the name of the environment. The default Pipelines deployment environments are test, staging, or production.

例:

pipelines: default: - step: name: Deploy to production deployment: production script: - python deployscript.py prod

bitbucket-pipelines.yml ファイルに対する変更をコミットし、デプロイ パイプラインを実行します。デプロイ ステップまたはステージがデプロイ ダッシュボードに表示されるようになります。

Bitbucket Pipelines で複数のデプロイ環境を追加する場合は、bitbucket-pipelines.yml ファイル内でデプロイを次のように順序付ける必要があります。

  1. テスト環境

  2. ステージング環境

  3. 本番環境

Pipelines では、3 つの環境タイプすべてが必要になるわけではなく、各タイプのステップとステージの順序は任意です。

たとえば、デプロイ設定ページで次のデプロイ環境が設定されているものとします。

  • テスト環境 — testbed

  • ステージング環境 — staging1 および staging2

  • 本番環境 — production-east

関連するステップやステージをパイプラインに追加する際には、ステージング環境 (staging1 および staging2) がテスト環境よりも後、本番環境よりも前にグループ化されていることを確認してください。

次に例を示します。

pipelines: default: - step: name: Build and push to S3 script: - apt-get update - apt-get install -y python-dev - curl -O https://bootstrap.pypa.io/get-pip.py - python get-pip.py - pip install awscli - aws deploy push --application-name $APPLICATION_NAME --s3-location s3://$S3_BUCKET/test_app_$BITBUCKET_BUILD_NUMBER --ignore-hidden-files - step: name: Deploy to testing image: amazon/aws-cli:latest deployment: testbed # Test environment script: - python deploy.py test - step: name: Deploy to staging image: amazon/aws-cli:latest deployment: staging2 # Staging environment trigger: manual script: - python deploy.py staging - step: name: Deploy to QA staging image: amazon/aws-cli:latest deployment: staging1 # Staging environment trigger: manual script: - python deploy.py staging - step: name: Deploy to production image: amazon/aws-cli:latest deployment: production-east # Production environment trigger: manual script: - python deploy.py prod

ステップ 3: デプロイを追跡する

Once your deployment step has run, you can track your deployments on the Deployments dashboard.

デプロイメント ダッシュボードを理解する

デプロイメント ダッシュボードを使用して、すべてのデプロイ環境の情報をひと目で確認できます。また、権限を持つデプロイ変数を使用して、特定のブランチやユーザーでのみデプロイを行えるようにできます。

デプロイメントのレビューとプロモーション

If you've made a deployment step manual, you will see a Promote button on the Deployments dashboard. Selecting the Promote button launches the deployment preview screen where you can review the commits and the file changes that will be deployed. If it looks good, select Deploy and we'll trigger your manual deployment step.

Note: you can only have one in-progress deployment in each environment. Any later pipelines that deploy to the same environment will be automatically paused. You can manually resume the paused deployment step once the in-progress deployment completes.

デプロイメント情報

環境カードからさまざまな情報にアクセスできます。

1. デプロイメント履歴

By selecting the environment name you can see a history of all earlier deployments to an environment. You can select on any of these to get a deployment summary.

2. パイプラインの表示

If you select on the pipeline number, it will take you to the summary for that run of the pipeline, where you can view logs and more.

3. デプロイメントの要約

Access the deployment summary by selecting the deployment on an environment card, or in the history list. The summary shows information about the deployment including:

  • デプロイ先の環境

  • 環境での過去のデプロイメント

  • デプロイメントのステータス

  • デプロイメントのトリガー実施者 (デプロイメントが手動ステップだった場合)

  • デプロイメントが発生した日付

  • デプロイメントのコミットの完全な一覧

  • 新しいデプロイメントと環境内の過去のデプロイメントのファイル差分

  • コミット メッセージでメンションしたリンクされている Jira 課題

どの環境でもデプロイされた最初のビルドには、そのビルドに関連付けられたコミットのみが表示されます。ビルドを再実行しても、これらのビルド間で違いはありません。そのため、そのビルドの差分は表示されません。

If you use Jira to keep track of work, you can link Jira and Bitbucket, for added benefits.

これらをリンクすると、デプロイメントに関連する課題がデプロイメントの概要とデプロイメントのプレビュー画面に表示され、デプロイメントが関連する Jira 課題に表示されます。コミット メッセージに課題キーまたはキーを追加すると、残りの処理は自動で行われます。

git commit -m "PT-323 Add created workers to container cluster"


Bitbucket では、これは次の画像のように表示されます。

bitbucket ビュー

Jira では、次のように表示されます。

Jira ビュー

成功したデプロイメントを再実行すると、Jira は再実行の結果ではなく、最初に成功したデプロイメントの詳細を引き続き表示します。

デプロイメントのロールバック

Bitbucket Pipelines allow you to roll back a deployment step without running the entire pipeline. If your deployment failed, you can restore the last successful deployment.

はじめる前に

[再デプロイ] ボタンを有効化するには、以下が必要です。

  • パイプラインの最初のデプロイメント ステップが正常に完了していること。

  • The deployment permissions must allow the step to be redeployed (Premium plan only)

  • アーティファクトが失効していないこと。

デプロイメントのロールバック

デプロイメント ステップをロールバックするには、次の手順を実行します。

  1. Choose the deployment which you want to redeploy and select the Redeploy button. 

  2. In the Redeploy screen, review the changes and select Redeploy:

再デプロイ

または、デプロイ ダッシュボードで [Redeploy (再デプロイ)] を選択してもかまいません。



ロールバック再デプロイ

 

さらにヘルプが必要ですか?

アトラシアン コミュニティをご利用ください。