Bitbucket PipelinesとCapgoの統合

Bitbucket Pipelines Integration

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

Bitbucketアカウントとリポジトリ

  • Capgoアカウントとアプリの設定
  • A Capgo account with an app configured
  • Node.js and npm/yarn configured in your project

セクション「Bitbucket Pipelinesの設定」

ステップ1: リポジトリ変数の設定

セクション「ステップ1: リポジトリ変数の設定」

まず、Bitbucketリポジトリ内で必要な変数を設定してください。

セクション「前提条件」

  1. Bitbucket リポジトリに移動してください
  2. リポジトリ設定Pipelinesリポジトリ変数
  3. 以下の変数を追加してください
変数名暗号化
CAPGO_TOKENあなたの Capgo API トークン✅ はい

コピー

# 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/**

__CAPGO_KEEP_0__ と __CAPGO_KEEP_1__ のトークンを取得

「機能ブランチのデプロイ」セクション

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

# 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_KEEP_0__」の暗号化機能を使用している場合 Capgo’s encryption feature__CAPGO_KEEP_0__

設定後 ローカルで暗号化キーを設定した後 ビットバケット変数にプライベートキーを追加してください

ターミナル画面
# Display your private key content (copy this output)
cat .capgo_key_v2

ビットバケットリポジトリ変数に次の内容を追加してください(マークして安全に保存) CAPGO_PRIVATE_KEY クリップボードにコピー

# 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

For comprehensive information about setting up and managing multiple deployment channels, see the Channels documentation.

Complete configuration with multiple environments and pull request deployments:

# 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 を定期的にローテーションする

__CAPGO_KEEP_0__の展開環境をセキュリティの向上のために設定する:

# 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統合から続けてのセクション

Bitbucket Pipelines統合を使用している場合 Bitbucket Pipelines統合 CI/CDの自動化を計画するには、 Capgo CI/CD Capgo CI/CDの製品ワークフロー Capgo ネイティブビルド Capgo ネイティブビルドの製品ワークフロー Capgo インテグレーション Capgo インテグレーションの製品ワークフロー CI/CD統合 CI/CD統合の実装詳細 GitHub アクション統合 GitHub アクション統合の実装詳細