Bitbucket Pipelines 集成
复制包含安装步骤和该插件完整 Markdown 指南的配置 prompt。
将 Capgo Live Updates 与 Bitbucket Pipelines 集成,即可在每次推送 code 变更时自动部署应用更新。本指南介绍如何配置自动化构建、测试和部署工作流。
前提条件
“前提条件”章节在设置 Bitbucket Pipelines 集成前,请确保已具备:
- 一个拥有代码仓库的 Bitbucket 账号
- 一个已配置好 App 的 Capgo 账号
- 项目中已配置 Node.js 和 npm/yarn
配置 Bitbucket Pipelines
标题为“设置 Bitbucket Pipelines”的章节第 1 步:配置仓库变量
“步骤 1:配置仓库变量”章节首先,在您的 Bitbucket 仓库中设置必要的变量:
- 前往您的 Bitbucket 仓库
- 前往 仓库设置 → Pipelines → 仓库变量
- 添加以下变量:
| 变量名 | 值 | Secured |
|---|---|---|
CAPGO_TOKEN | 你的 Capgo API token | ✅ 是 |
每次 push 到 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/**进阶
“高级”章节特性分支部署
“功能分支部署”章节将功能分支部署到测试频道,以便评审和测试:
# 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 add $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 并存入 Bitbucket 仓库变量(设为加密),然后在 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多通道配置
标题为“多通道配置”的章节如需全面了解如何设置和管理多个部署渠道,请参阅 Channels 文档.
完成多环境与 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 add $CHANNEL_NAME --apikey $CAPGO_TOKEN || true - npx @capgo/cli bundle upload --apikey $CAPGO_TOKEN --channel $CHANNEL_NAME artifacts: - dist/**多环境 Pipeline
“多环境流水线”章节针对包含 staging 和 production 环境的复杂部署场景:
# 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/**基于分支的部署策略
“基于分支的部署策略”章节自动将不同分支部署到对应的 channel:
# 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/**并行 Pipeline 执行
“并行流水线执行”章节通过并行步骤优化 build 时间:
# 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安全最佳实践
“安全最佳实践”章节- 安全变量: 请务必将 API token 标记为安全变量
- 环境变量: 必要时使用特定部署环境的变量
- 访问控制: 仅限授权团队成员访问仓库
- Token 轮换: 定期轮换您的 Capgo API token
部署环境
“部署环境”章节配置部署环境以提升安全性:
# 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 production监控与通知
标题为“监控与通知”的章节Slack 集成
标题为“Slack 集成”的章节在您的 pipeline 中添加 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 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"Pipeline 调试
“调试 Pipeline”章节添加调试信息以排查问题:
# 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 productionPipeline 校验
“Pipeline 校验”章节启用 Pipeline 校验以捕获配置错误:
# 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 集成
“通过 Bitbucket Pipelines 集成持续构建”章节如果你正在使用 Bitbucket Pipelines 集成 规划 CI/CD 自动化,并将其与 Capgo CI/CD 用于 Capgo CI/CD 中的产品工作流, Capgo Native Build 用于 Capgo Native Builds 中的产品工作流, Capgo 集成 用于 Capgo 集成中的产品工作流, CI/CD 集成 了解 CI/CD 集成的实现细节,以及 GitHub Actions 集成 有关 GitHub Actions 集成的实现细节。