Skip to content

Bitbucket Pipelines統合

CapgoのライブアップデートとBitbucket Pipelinesを組み合わせて、codeの変更をプッシュしたときに自動的にアプリのアップデートをデプロイすることができます。このガイドでは、自動ビルド、テスト、デプロイワークフローの設定について説明します。

Bitbucket Pipelinesの統合を設定する前に、次のことを確認してください。

  • Bitbucketアカウントとリポジトリ
  • アプリが設定されたCapgoアカウント
  • Node.jsとnpm/yarnがプロジェクトに設定されている

最初に、ビットバケット リポジトリで必要な変数を設定してください。

  1. ビットバケット リポジトリに移動してください。
  2. Go to リポジトリ設定Pipelinesリポジトリ変数
  3. 次の変数を追加してください。
変数名セキュア
CAPGO_TOKENあなたのCapgo APIトークン✅ Yes

基本的な構成は、メインブランチにプッシュするたびにプロダクションにデプロイされます:

# bitbucket-pipelines.yml - Simple Configuration
image: 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/**

機能ブランチをテストチャンネルにデプロイしてレビューとテストを行います:

# Feature branch deployment
pipelines:
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/**

あなたが Capgoの暗号化機能を使用している場合、あなたはCI/CD環境であなたのプライベートキーを安全に保存する必要があります。

暗号化キーを 設定した後、ローカルにプライベートキーを追加し、Bitbucket変数にプライベートキーを追加する必要があります: ターミナル画面

コピー
# Display your private key content (copy this output)
cat .capgo_key_v2

コピーする CAPGO_PRIVATE_KEY In your Bitbucket repository variables (mark as secured), then use it in pipelines:

# 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

https://github.com/__CAPGO_KEEP_0__ チャンネルドキュメント.

複数環境とプルリクエストデプロイメントをサポートする完全な構成:

# bitbucket-pipelines.yml - Advanced Multi-Channel Configuration
image: 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/**

ステージングとプロダクション環境を含む複雑なデプロイシナリオの場合:

# Multi-environment pipeline
image: 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/**

自動的に適切なチャンネルに異なるブランチをデプロイ:

# Dynamic channel deployment
image: 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/**

並列パイプライン実行

並列パイプライン実行セクション

並列ステップを使用してビルド時間を最適化します:

# Parallel execution pipeline
image: 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

セキュリティのベストプラクティス

セキュリティのベストプラクティスセクション
  1. セキュア化された変数APIを常にマークしてセキュア化します
  2. 環境変数: 必要に応じてデプロイメント固有の変数を使用します
  3. アクセス制御: リポジトリへのアクセスを承認されたチーム メンバーに制限する
  4. トークン ローテーション: 定期的に Capgo API トークンをローテーションする

デプロイメント エンドポイント

「デプロイメント エンドポイント」セクション

セキュリティの向上のためにデプロイメント エンドポイントを設定する:

# Deployment with environment restrictions
pipelines:
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 production

パイプラインにSlack通知を追加する:

# Pipeline with Slack notifications
pipelines:
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
fi

Bitbucketの組み込み機能または外部サービスを使用してメール通知を設定します。

# 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]

Pipelineが「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"

問題をトラブルシューティングするためにデバッグ情報を追加する:

# Debug pipeline
pipelines:
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

パイプライン検証を有効にすることで構成エラーをキャッチする:

# Enable pipeline validation
options:
docker: true
size: 2x
pipelines:
branches:
main:
- step:
name: Validate Pipeline
script:
- echo "Pipeline validation successful"
- step:
name: Build and Deploy
script:
# ... deployment steps

次のステップ

次のステップ

Bitbucket Pipelines統合を使用すると、Capgoのデプロイを自動化し、モバイルアプリのユーザーに安定した更新を保証できます。

Bitbucket Pipelines統合を使用している場合 Bitbucket Pipelines統合 CI/CDの自動化を計画するには、Bitbucket Pipelines統合を__CAPGO_KEEP_0__ CI/CDに接続する Capgo CI/CDの製品ワークフロー Capgo Native Buildsの製品ワークフロー Capgo Native Buildsの製品ワークフロー Capgo Integrationsの製品ワークフロー CI/CDの自動化を計画するには、Bitbucket Pipelines統合をCapgo CI/CDに接続する Capgoの製品ワークフローにおける統合 CI/CD統合 __CAPGO_KEEP_0__ Actions統合の実装詳細について GitHub Actions統合 GitHub Actions統合の実装詳細について