Bitbucket Pipelines 集成
复制一个包含安装步骤和本插件的完整 Markdown 指南的配置提示。
将 Capgo Live Updates 与 Bitbucket Pipelines 集成,以便在推送 code 变更时自动部署您的应用程序更新。 本指南涵盖了设置自动构建、测试和部署工作流程。
前提条件
标题为“前提条件”在设置 Bitbucket Pipelines 集成之前,请确保您有:
- 拥有 Bitbucket 帐户和仓库
- 拥有 Capgo 帐户和已配置的应用
- Node.js 和 npm/yarn 已在项目中配置
设置 Bitbucket Pipelines
设置 Bitbucket Pipelines步骤 1:配置仓库变量
步骤 1:配置仓库变量首先,在您的 Bitbucket 仓库中设置必要的变量:
- 前往您的 Bitbucket 仓库
- 前往 仓库设置 → 管道 → 仓库变量
- 添加以下变量:
| 变量名称 | 值 | 安全 |
|---|---|---|
CAPGO_TOKEN | 您的 Capgo API token | ✅ 是 |
简单
简单基本配置,部署到生产环境每次推送到主分支:
# 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/**高级
高级功能分支部署
功能分支部署将功能分支部署到测试频道进行审查和测试:
# 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/**使用加密
标题:使用加密如果您正在使用 Capgo的加密功能,您需要在CI/CD环境中安全存储您的私钥。
在 设置加密密钥 本地后,添加您的私钥到Bitbucket变量中:
# Display your private key content (copy this output)cat .capgo_key_v2将此内容添加为 CAPGO_PRIVATE_KEY In您的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多渠道配置
多渠道配置有关设置和管理多个部署通道的详细信息,请参见 频道文档.
支持多环境和 pull request 部署:
# 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/**多环境管道
多环境管道适用于具有 staging 和生产环境的复杂部署场景:
# 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/**基于分支的部署策略
基于分支的部署策略自动将不同分支部署到适当的频道:
# 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/**并行管道执行
并行管道执行并行步骤优化构建时间:
# 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安全最佳实践
安全最佳实践仓库变量
安全变量- : 总是将 __CAPGO_KEEP_0__ 标记为安全: Always mark API tokens as secured
- 访问控制安全变量:总是将__CAPGO_KEEP_0__标记为安全
- 环境变量:使用需要的部署特定变量: 限制仓库访问权限给授权团队成员
- Token Rotation: 定期轮换您的 Capgo API token
Deployment Environments
Deployment Environments配置部署环境以提高安全性:
# 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 productionMonitoring and Notifications
监控和通知Section titled “Monitoring and Notifications”
Slack IntegrationSlack 集成:
# 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 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]故障排除
标题:故障排除常见问题
标题:常见问题管道失败时显示“Capgo CLI 未找到”:
# 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 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管道验证
管道验证启用管道验证以捕获配置错误:
# 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下一步
下一步通过Bitbucket Pipelines集成,您可以自动化Capgo的部署并确保您的移动应用程序用户接收到一致可靠的更新。
从Bitbucket Pipelines Integration继续
标题:从Bitbucket Pipelines Integration继续如果您正在使用 Bitbucket Pipelines Integration 来规划CI/CD自动化,连接它到 Capgo CI/CD 来规划Capgo CI/CD中的产品工作流程 Capgo Native Builds 来规划Capgo Native Builds中的产品工作流程 Capgo Integrations 为产品工作流程在Capgo Integrations中, CI/CD Integration 为CI/CD Integrations的实施细节, GitHub Actions Integration 为GitHub Actions Integrations的实施细节,