Pipelines の使用方法 - 例とガイド

robotsnoindex

お客様のインスピレーションに役立つ、Bitbucket Pipelines のユースケースを集めました。yaml ファイルの構築例、パイプラインの動作例を確認できる複数の実際のリポジトリ、Bitbucket Pipelines の使用方法について議論している世界中のユーザーによる多数の投稿などをご確認いたあけます。

bitbucket-pipelines.yml ファイルの例

テスト環境に自動的にデプロイし、リリース ブランチからステージングおよび本番環境に手動でデプロイ

一般に、すべてのコミットは default パイプラインをトリガーする開発ブランチで発生します。このパイプラインはビルドとテストを行い、成功した場合は、スクリプトを自動的に実行して開発環境にデプロイします。

次に、すべてのコードを 1 つの release ブランチにマージし、ボタンのクリックで段階的なデプロイを行います (trigger: manual オプションを削除して自動的にデプロイできます)。

image: <Whatever Docker build image you need>
pipelines:
  branches:
    release: # This pipeline has 3 steps.
      - step:
          name: Build & test
          script:
            - ./run-build
            - ./run-tests
          artifacts: # This will carry across the files you want to deploy to all subsequent steps
            - ~/build/files-to-deploy/*
      - step:
          name: Deploy to Test
          deployment: test
          trigger: manual # This step needs to be started on the UI. Remove this line to have it run automatically.
          script:
            - ./deploy-to-test
      - step:
          name: Deploy to Staging
          deployment: staging
          trigger: manual # This step needs to be started on the UI. Remove this line to have it run automatically.
          script:
            - ./deploy-to-staging
      - step:
          name: Deploy to Production
          deployment: production
          trigger: manual
          script:
            - ./deploy-to-production
  default:
    - step:
        name: Build & test
        script:
          - ./run-build
          - ./run-tests

その他のリソース

ステージング ブランチからステージング サーバーに、master ブランチから本番環境にデプロイ

ステージングと開発に別のブランチを使用しており、staging ブランチへのプッシュでステージング サーバーへのデプロイをトリガーし、master へのプッシュで本番サーバーへのデプロイをトリガーしたい場合。

この構成は次の内容を実現します。

  • master へのプッシュで master ブランチ パイプラインを実行して本番環境にデプロイ
  • staging へのプッシュでステージング ブランチパイプラインを実行してステージングにデプロイ
  • 他の任意のブランチへのプッシュで、ビルドおよびテスト ステップのみを実行するデフォルトのパイプラインを実行
pipelines:
  default: # the default pipeline will just run your build and test commands
    - step:
        name: Build and test
        script:
          - ./run-build
          - ./run-tests
  branches:
    staging: # this staging branch pipeline will deploy to the staging environment
      - step:
          name: Build and test
          script:
            - ./run-build
            - ./run-tests
          artifacts: # This will carry across the files you want to deploy to all subsequent steps
            - ~/build/files-to-deploy/*
      - step:
          name: Deploy to Staging
          deployment: staging
          script:
            - ./deploy-to-staging
    master: # this master branch pipeline will deploy to the production environment
      - step:
          name: Build and test
          script:
            - ./run-build
            - ./run-tests
          artifacts:
            - ~/build/files-to-deploy/*
      - step:
          name: Deploy to Production
          deployment: production
          script:
            - ./deploy-to-production

デプロイ ステップでは (deployment キーワードを使用して) それぞれの環境が示されているため、Bitbucket のデプロイメント ダッシュボードでこれらの環境のステータスを追跡することもできます。

yaml ファイルはプッシュが発生するブランチから読み込まれます。この構成をステージング ブランチと master ブランチの両方にマージするようにします。

共有スクリプトや yml アンカーを使用してクリーンアップできる、重複のステップ定義もあります。


サンプル リポジトリ

パイプラインを使用して Docker イメージを作成してリリースするライブラリ。

これは、バージョン アップデートにパイプラインを使用している実際の例です (このライブラリが実際に実現する内容の詳細については、「indexer sidecar for Elasticsearch」で作成者の投稿をご確認ください)。

他のユーザーによるガイド

さまざまなユーザーがパイプラインの可能性を探索し、自身の体験を共有してくださっています。アトラシアン以外のユーザーが作成したガイドをいくつか紹介します。

最終更新日 2020 年 6 月 24 日

この内容はお役に立ちましたか?

はい
いいえ
この記事についてのフィードバックを送信する
Powered by Confluence and Scroll Viewport.