Bitbucket Pipelines統合
Capgo Live UpdatesをBitbucket Pipelinesと統合して、コード変更をプッシュするたびにアプリのアップデートを自動的にデプロイします。このガイドでは、自動ビルド、テスト、デプロイメントワークフローの設定について説明します。
Bitbucket Pipelines統合を設定する前に、以下を確認してください:
- リポジトリを持つBitbucketアカウント
- アプリが構成されたCapgoアカウント
- プロジェクトでNode.jsとnpm/yarnが構成されていること
Bitbucket Pipelinesの設定
Section titled “Bitbucket Pipelinesの設定”ステップ1: リポジトリ変数の構成
Section titled “ステップ1: リポジトリ変数の構成”まず、Bitbucketリポジトリで必要な変数を設定します:
- Bitbucketリポジトリに移動
- Repository settings → Pipelines → Repository variablesに移動
- 以下の変数を追加:
| 変数名 | 値 | セキュア |
|---|---|---|
CAPGO_TOKEN | Capgo APIトークン | ✅ はい |
mainブランチへのプッシュごとに本番環境にデプロイする基本構成:
# bitbucket-pipelines.yml - Simple Configurationimage: node:22
pipelines: branches: main: - step: name: Build and Deploy to Production script: - npm ci - npm run test - npm run build - npm install -g @capgo/cli - npx @capgo/cli bundle upload --apikey $CAPGO_TOKEN --channel production artifacts: - dist/**フィーチャーブランチのデプロイメント
Section titled “フィーチャーブランチのデプロイメント”レビューとテストのためにフィーチャーブランチをテストチャネルにデプロイ:
# Feature branch deploymentpipelines: branches: feature/*: - step: name: Deploy Feature Branch script: - npm ci - npm run test - npm run build - BRANCH_NAME=$(echo $BITBUCKET_BRANCH | sed 's/[^a-zA-Z0-9-]/-/g') - CHANNEL_NAME="feature-$BRANCH_NAME" - npm install -g @capgo/cli - npx @capgo/cli channel create $CHANNEL_NAME --apikey $CAPGO_TOKEN || true - npx @capgo/cli bundle upload --apikey $CAPGO_TOKEN --channel $CHANNEL_NAME artifacts: - dist/**暗号化の使用
Section titled “暗号化の使用”Capgoの暗号化機能を使用している場合、CI/CD環境にプライベートキーを安全に保存する必要があります。
ローカルで暗号化キーを設定した後、プライベートキーをBitbucket変数に追加します:
# プライベートキーの内容を表示(この出力をコピー)cat .capgo_key_v2この内容をCAPGO_PRIVATE_KEYとしてBitbucketリポジトリ変数に追加し(セキュアとしてマーク)、パイプラインで使用します:
# Deploy with encryption- step: name: Deploy to Capgo with Encryption script: - npm install -g @capgo/cli - npx @capgo/cli bundle upload --apikey $CAPGO_TOKEN --key-data-v2 "$CAPGO_PRIVATE_KEY" --channel productionマルチチャネル構成
Section titled “マルチチャネル構成”複数のデプロイメントチャネルの設定と管理に関する包括的な情報については、チャネルドキュメントを参照してください。
複数の環境とプルリクエストのデプロイメントを含む完全な構成:
# bitbucket-pipelines.yml - Advanced Multi-Channel Configurationimage: node:22
definitions: steps: - step: &build-step name: Build Application script: - npm ci - npm run test - npm run build artifacts: - dist/**
- step: &deploy-step name: Deploy to Capgo script: - npm install -g @capgo/cli - npx @capgo/cli bundle upload --apikey $CAPGO_TOKEN --channel $CHANNEL_NAME
pipelines: branches: main: - step: <<: *build-step - step: <<: *deploy-step name: Deploy to Production deployment: production trigger: manual script: - export CHANNEL_NAME=production - npm install -g @capgo/cli - npx @capgo/cli bundle upload --apikey $CAPGO_TOKEN --channel $CHANNEL_NAME
develop: - step: <<: *build-step - step: <<: *deploy-step name: Deploy to Development deployment: development script: - export CHANNEL_NAME=development - npm install -g @capgo/cli - npx @capgo/cli bundle upload --apikey $CAPGO_TOKEN --channel $CHANNEL_NAME
pull-requests: '**': - step: <<: *build-step - step: name: Deploy PR to Test Channel script: - CHANNEL_NAME="pr-$BITBUCKET_PR_ID" - npm install -g @capgo/cli - npx @capgo/cli channel create $CHANNEL_NAME --apikey $CAPGO_TOKEN || true - npx @capgo/cli bundle upload --apikey $CAPGO_TOKEN --channel $CHANNEL_NAME artifacts: - dist/**マルチ環境パイプライン
Section titled “マルチ環境パイプライン”ステージングと本番環境を持つ複雑なデプロイメントシナリオの場合:
# Multi-environment pipelineimage: node:22
pipelines: branches: main: - step: name: Build script: - npm ci - npm run test - npm run build artifacts: - dist/** - step: name: Deploy to Staging deployment: staging script: - npm install -g @capgo/cli - npx @capgo/cli bundle upload --apikey $CAPGO_TOKEN --channel staging - step: name: Deploy to Production deployment: production trigger: manual script: - npm install -g @capgo/cli - npx @capgo/cli bundle upload --apikey $CAPGO_TOKEN --channel production
develop: - step: name: Build and Deploy to Development script: - npm ci - npm run test - npm run build - npm install -g @capgo/cli - npx @capgo/cli bundle upload --apikey $CAPGO_TOKEN --channel development artifacts: - dist/**ブランチベースのデプロイメント戦略
Section titled “ブランチベースのデプロイメント戦略”異なるブランチを適切なチャネルに自動的にデプロイ:
# Dynamic channel deploymentimage: node:22
definitions: scripts: - script: &determine-channel | if [ "$BITBUCKET_BRANCH" = "main" ]; then export CHANNEL_NAME="production" elif [ "$BITBUCKET_BRANCH" = "develop" ]; then export CHANNEL_NAME="staging" else export CHANNEL_NAME="development" fi echo "Deploying to channel: $CHANNEL_NAME"
pipelines: default: - step: name: Build and Deploy script: - npm ci - npm run test - npm run build - *determine-channel - npm install -g @capgo/cli - npx @capgo/cli bundle upload --apikey $CAPGO_TOKEN --channel $CHANNEL_NAME artifacts: - dist/**パラレルパイプライン実行
Section titled “パラレルパイプライン実行”パラレルステップでビルド時間を最適化:
# Parallel execution pipelineimage: node:22
pipelines: branches: main: - parallel: - step: name: Run Tests script: - npm ci - npm run test - step: name: Lint Code script: - npm ci - npm run lint - step: name: Build Application script: - npm ci - npm run build artifacts: - dist/** - step: name: Deploy to Production deployment: production script: - npm install -g @capgo/cli - npx @capgo/cli bundle upload --apikey $CAPGO_TOKEN --channel productionセキュリティのベストプラクティス
Section titled “セキュリティのベストプラクティス”リポジトリ変数
Section titled “リポジトリ変数”- セキュア変数: APIトークンは常にセキュアとしてマーク
- 環境変数: 必要に応じてデプロイメント固有の変数を使用
- アクセス制御: リポジトリアクセスを承認されたチームメンバーに制限
- トークンのローテーション: Capgo APIトークンを定期的にローテーション
デプロイメント環境
Section titled “デプロイメント環境”より良いセキュリティのためにデプロイメント環境を構成:
# Deployment with environment restrictionspipelines: branches: main: - step: name: Deploy to Production deployment: production trigger: manual script: - npm install -g @capgo/cli - npx @capgo/cli bundle upload --apikey $CAPGO_TOKEN --channel productionSlack統合
Section titled “Slack統合”パイプラインにSlack通知を追加:
# Pipeline with Slack notificationspipelines: branches: main: - step: name: Build and Deploy script: - npm ci - npm run test - npm run build - npm install -g @capgo/cli - npx @capgo/cli bundle upload --apikey $CAPGO_TOKEN --channel production after-script: - | if [ $BITBUCKET_EXIT_CODE -eq 0 ]; then curl -X POST -H 'Content-type: application/json' \ --data '{"text":"✅ Capgo deployment successful for '$BITBUCKET_BRANCH'"}' \ $SLACK_WEBHOOK_URL else curl -X POST -H 'Content-type: application/json' \ --data '{"text":"❌ Capgo deployment failed for '$BITBUCKET_BRANCH'"}' \ $SLACK_WEBHOOK_URL fiBitbucketの組み込み機能または外部サービスを使用してメール通知を構成:
# Email notification step- step: name: Send Notification script: - | curl -X POST \ -H "Content-Type: application/json" \ -d '{ "to": "team@yourcompany.com", "subject": "Capgo Deployment Status", "body": "Deployment of '$BITBUCKET_BRANCH' completed with status: '$BITBUCKET_EXIT_CODE'" }' \ $EMAIL_SERVICE_URL condition: result: [successful, failed]トラブルシューティング
Section titled “トラブルシューティング”一般的な問題
Section titled “一般的な問題”「Capgo CLI not found」でパイプラインが失敗:
# Debug CLI installation- step: name: Debug CLI script: - npm install -g @capgo/cli - which capgo || echo "Capgo CLI not found" - npx @capgo/cli --version認証エラー:
# Verify token configuration- step: name: Debug Auth script: - | if [ -z "$CAPGO_TOKEN" ]; then echo "CAPGO_TOKEN is not set" exit 1 fi echo "Token length: ${#CAPGO_TOKEN}"ビルドアーティファクトが見つからない:
# List build outputs- step: name: Debug Build script: - ls -la dist/ - find dist/ -type f -name "*.js" -o -name "*.html"デバッグパイプライン
Section titled “デバッグパイプライン”問題をトラブルシューティングするためのデバッグ情報を追加:
# Debug pipelinepipelines: branches: main: - step: name: Debug Information script: - echo "Branch: $BITBUCKET_BRANCH" - echo "Commit: $BITBUCKET_COMMIT" - echo "Build: $BITBUCKET_BUILD_NUMBER" - env | grep BITBUCKET_ | sort - step: name: Build and Deploy script: - npm ci - npm run test - npm run build - npm install -g @capgo/cli - npx @capgo/cli bundle upload --apikey $CAPGO_TOKEN --channel productionパイプライン検証
Section titled “パイプライン検証”構成エラーを検出するためにパイプライン検証を有効化:
# Enable pipeline validationoptions: docker: true size: 2x
pipelines: branches: main: - step: name: Validate Pipeline script: - echo "Pipeline validation successful" - step: name: Build and Deploy script: # ... deployment steps次のステップ
Section titled “次のステップ”- チャネルについて学び、異なるデプロイメント環境を管理
- 高度なデプロイメントシナリオのためのカスタムストレージを探索
- 安全なデプロイメントのための暗号化を設定
- アップデートの適用方法をカスタマイズするためのアップデート動作を構成
Bitbucket Pipelines統合により、Capgoデプロイメントを自動化し、モバイルアプリユーザーへの一貫性のある信頼性の高いアップデートを保証できます。