Pipelines の使用方法 - 例とガイド
Bitbucket Pipelines を使い始める
このページの内容
robots | noindex |
お客様のインスピレーションに役立つ、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
その他のリソース
- Branch workflows: https://confluence.atlassian.com/bitbucket/branch-workflows-856697482.html
- Deployments: https://confluence.atlassian.com/bitbucket/bitbucket-deployments-940695276.html
- Artifacts: https://confluence.atlassian.com/bitbucket/using-artifacts-in-steps-935389074.html
- Manual triggers (see the 'Manual Step' section): https://confluence.atlassian.com/bitbucket/run-pipelines-manually-861242583.html
- bitbucket-pipelines.yml configuration: https://confluence.atlassian.com/bitbucket/configure-bitbucket-pipelines-yml-792298910.html
ステージングと開発に別のブランチを使用しており、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」で作成者の投稿をご確認ください)。
他のユーザーによるガイド
さまざまなユーザーがパイプラインの可能性を探索し、自身の体験を共有してくださっています。アトラシアン以外のユーザーが作成したガイドをいくつか紹介します。
- Building a Bitbucket Pipe as a casual coder
- Make an app in expo, test it, and then deploy it
- Build and deploy maven artifacts to CloudRepo
- How to publish Ruby Gems from Bitbucket Pipelines
- Deploy your Angular App to Firebase hosting via BitBucket Pipelines
- Continuous Deployment Pipeline to AWS EC2 using AWS Code Deploy
- Deploy to GCP Cloud Run with Bitbucket Pipelines