Azure DevOps Integration
复制一个包含安装步骤和本插件的完整 Markdown 指南的配置提示。
将 Capgo Live Updates 与 Azure DevOps Pipelines 集成,以便在推送 code 更改时自动部署您的应用程序更新。 本指南涵盖了设置自动构建、测试和部署工作流程。
前置条件
标题:前置条件在设置 Azure DevOps 集成之前,请确保您有:
- 一个 Azure DevOps 组织和项目
- 一个 Capgo 帐户,配置了应用程序
- 您的应用程序的源 code 位于 Azure Repos Git 存储库中
- Node.js 和 npm/yarn 已在项目中配置
设置 Azure DevOps Pipeline
标题:设置 Azure DevOps Pipeline步骤 1:创建管道变量
步骤 1:创建管道变量首先,在您的 Azure DevOps 项目中设置必要的变量:
- 导航到您的 Azure DevOps 项目
- 前往 管线 → 库 → 变量组
- 创建一个名为的新变量组:
Capgo-Variables - 添加以下变量:
| 变量名称 | 值 | 安全 |
|---|---|---|
CAPGO_TOKEN | 您的 Capgo API token | ✅ 是 |
简单
标题为“简单”基本配置,部署到生产环境每次推送到主分支:
# Simple Azure DevOps Pipeline for Capgo Live Updatestrigger: branches: include: - main
variables: - group: Capgo-Variables
jobs: - job: BuildAndDeploy displayName: 'Build and Deploy to Capgo' pool: vmImage: 'ubuntu-latest'
steps: - task: NodeTool@0 displayName: 'Setup Node.js' inputs: versionSpec: '22.x'
- script: | npm ci npm run test npm run build displayName: 'Install, test and build'
- script: | npm install -g @capgo/cli npx @capgo/cli bundle upload --apikey $(CAPGO_TOKEN) --channel production displayName: 'Deploy to Capgo'高级
高级功能分支部署
功能分支部署将功能分支部署到测试频道进行审查和测试:
# Feature branch deploymenttrigger: branches: include: - feature/*
variables: - group: Capgo-Variables
jobs: - job: DeployFeature displayName: 'Deploy Feature Branch' pool: vmImage: 'ubuntu-latest' condition: startsWith(variables['Build.SourceBranch'], 'refs/heads/feature/')
steps: - task: NodeTool@0 inputs: versionSpec: '22.x'
- script: | npm ci npm run test npm run build displayName: 'Install, test and build'
- script: | BRANCH_NAME=$(echo "$(Build.SourceBranchName)" | 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 displayName: 'Deploy to Feature Channel'使用加密
使用加密如果您正在使用 Capgo的加密功能,您需要在CI/CD环境中安全存储您的私钥。
在 设置加密密钥 后,
# Display your private key content (copy this output)cat .capgo_key_v2复制到剪贴板 CAPGO_PRIVATE_KEY 将此内容添加为
# Deploy with encryption- script: | npm install -g @capgo/cli npx @capgo/cli bundle upload --apikey $(CAPGO_TOKEN) --key-data-v2 "$(CAPGO_PRIVATE_KEY)" --channel production displayName: 'Deploy to Capgo with Encryption'多渠道配置
多渠道配置有关设置和管理多个部署通道的详细信息,请参阅 Channels 文档.
多环境和拉取请求部署的完整配置:
# Advanced Azure DevOps Pipeline with Multiple Channelstrigger: branches: include: - main - develop
pr: branches: include: - main - develop
variables: - group: Capgo-Variables
stages: # Build stage - stage: Build jobs: - job: BuildApp pool: vmImage: 'ubuntu-latest' steps: - task: NodeTool@0 inputs: versionSpec: '22.x'
- script: | npm ci npm run test npm run build displayName: 'Install, test and build'
- task: PublishBuildArtifacts@1 inputs: pathToPublish: 'dist' artifactName: 'app-build'
# Deploy to development - stage: DeployDev condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/develop')) jobs: - deployment: DeployDevelopment environment: development pool: vmImage: 'ubuntu-latest' strategy: runOnce: deploy: steps: - task: NodeTool@0 inputs: versionSpec: '22.x'
- task: DownloadBuildArtifacts@0 inputs: artifactName: 'app-build' downloadPath: '$(Pipeline.Workspace)'
- script: | npm install -g @capgo/cli npx @capgo/cli bundle upload --apikey $(CAPGO_TOKEN) --channel development --path $(Pipeline.Workspace)/app-build displayName: 'Deploy to Development'
# Deploy PR to test channel - stage: DeployPR condition: and(succeeded(), eq(variables['Build.Reason'], 'PullRequest')) jobs: - job: DeployPRChannel pool: vmImage: 'ubuntu-latest' steps: - task: NodeTool@0 inputs: versionSpec: '22.x'
- task: DownloadBuildArtifacts@0 inputs: artifactName: 'app-build' downloadPath: '$(Pipeline.Workspace)'
- script: | CHANNEL_NAME="pr-$(System.PullRequest.PullRequestNumber)" 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 --path $(Pipeline.Workspace)/app-build displayName: 'Deploy to PR Channel'
# Deploy to production - stage: DeployProd condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/main')) jobs: - deployment: DeployProduction environment: production pool: vmImage: 'ubuntu-latest' strategy: runOnce: deploy: steps: - task: NodeTool@0 inputs: versionSpec: '22.x'
- task: DownloadBuildArtifacts@0 inputs: artifactName: 'app-build' downloadPath: '$(Pipeline.Workspace)'
- script: | npm install -g @capgo/cli npx @capgo/cli bundle upload --apikey $(CAPGO_TOKEN) --channel production --path $(Pipeline.Workspace)/app-build displayName: 'Deploy to Production'多环境部署
多环境部署对于复杂的场景,涉及多个环境:
# Extended pipeline with multiple environmentsparameters: - name: deployEnvironment displayName: 'Deploy Environment' type: string default: 'staging' values: - staging - production
variables: - group: Capgo-Variables - name: channelName ${{ if eq(parameters.deployEnvironment, 'production') }}: value: 'production' ${{ else }}: value: 'staging'
stages: # Build stage - stage: Build jobs: - job: BuildApp pool: vmImage: 'ubuntu-latest' steps: - task: NodeTool@0 inputs: versionSpec: '22.x'
- script: | npm ci npm run test npm run build displayName: 'Install, test and build'
- task: PublishBuildArtifacts@1 inputs: pathToPublish: 'dist' artifactName: 'app-build'
- stage: DeployStaging displayName: 'Deploy to Staging' dependsOn: Build condition: and(succeeded(), eq('${{ parameters.deployEnvironment }}', 'staging')) jobs: - deployment: DeployStaging displayName: 'Deploy to Staging Channel' pool: vmImage: 'ubuntu-latest' environment: 'staging' strategy: runOnce: deploy: steps: - template: deploy-steps.yml parameters: channel: 'staging'
- stage: DeployProduction displayName: 'Deploy to Production' dependsOn: Build condition: and(succeeded(), eq('${{ parameters.deployEnvironment }}', 'production')) jobs: - deployment: DeployProduction displayName: 'Deploy to Production Channel' pool: vmImage: 'ubuntu-latest' environment: 'production' strategy: runOnce: deploy: steps: - template: deploy-steps.yml parameters: channel: 'production'部署模板(deploy-steps.yml)
部署模板(deploy-steps.yml)创建可重用的模板文件 deploy-steps.yml:
parameters: - name: channel type: string
steps: - task: NodeTool@0 displayName: 'Install Node.js' inputs: versionSpec: '22.x'
- task: DownloadBuildArtifacts@0 displayName: 'Download build artifacts' inputs: artifactName: 'app-build' downloadPath: '$(System.ArtifactsDirectory)'
- script: | npm install -g @capgo/cli displayName: 'Install Capgo CLI'
- script: | npx @capgo/cli bundle upload \ --apikey $(CAPGO_TOKEN) \ --channel ${{ parameters.channel }} \ --path $(System.ArtifactsDirectory)/app-build displayName: 'Upload to Capgo (${{ parameters.channel }})'分支部署策略
分支部署策略根据 Git Branches 配置不同的部署策略:
trigger: branches: include: - main - develop - feature/*
variables: - group: Capgo-Variables - name: targetChannel ${{ if eq(variables['Build.SourceBranch'], 'refs/heads/main') }}: value: 'production' ${{ elseif eq(variables['Build.SourceBranch'], 'refs/heads/develop') }}: value: 'staging' ${{ else }}: value: 'development'
stages: - stage: Build jobs: - job: BuildApp pool: vmImage: 'ubuntu-latest' steps: - task: NodeTool@0 inputs: versionSpec: '22.x'
- script: | npm ci npm run test npm run build displayName: 'Install, test and build'
- task: PublishBuildArtifacts@1 inputs: pathToPublish: 'dist' artifactName: 'app-build'
- stage: Deploy displayName: 'Deploy to $(targetChannel)' dependsOn: Build condition: succeeded() jobs: - deployment: DeployJob displayName: 'Deploy to $(targetChannel) Channel' pool: vmImage: 'ubuntu-latest' environment: '$(targetChannel)' strategy: runOnce: deploy: steps: - template: deploy-steps.yml parameters: channel: '$(targetChannel)'安全最佳实践
安全最佳实践安全变量管理
安全变量管理- 使用变量组: 在 Azure DevOps 变量组中存储敏感数据
- 标记为机密: 始终将 API 令牌和密钥标记为机密变量
- 访问范围: 限制变量组访问到特定的管道和用户
- 旋转密钥定期旋转您的CapgoAPI令牌
监控和通知
监控和通知部分团队集成
团队集成部分将 Microsoft Teams 通知添加到管道中:
- task: ms-teams-deploy-card@1.4.1 displayName: 'Notify Teams on Success' condition: succeeded() inputs: webhookUri: '$(TEAMS_WEBHOOK_URL)' title: 'Capgo Deployment Successful' text: 'App deployed to $(targetChannel) channel' themeColor: '00FF00'
- task: ms-teams-deploy-card@1.4.1 displayName: 'Notify Teams on Failure' condition: failed() inputs: webhookUri: '$(TEAMS_WEBHOOK_URL)' title: 'Capgo Deployment Failed' text: 'Deployment to $(targetChannel) failed' themeColor: 'FF0000'电子邮件通知
电子邮件通知部分配置部署状态的电子邮件通知:
- task: EmailReport@1 displayName: 'Send Email Report' condition: always() inputs: sendMailConditionConfig: 'Always' subject: 'Capgo Deployment Report - $(Build.BuildNumber)' to: 'team@yourcompany.com' body: | Deployment Status: $(Agent.JobStatus) Channel: $(targetChannel) Build: $(Build.BuildNumber) Commit: $(Build.SourceVersion)故障排除
故障排除常见问题
常见问题管道失败:“Capgo CLI 未找到”
# Ensure global installation- script: | npm install -g @capgo/cli which capgo || echo "Capgo CLI not found in PATH" displayName: 'Install and verify Capgo CLI'认证错误:
# Verify token is correctly set- script: | echo "Token length: ${#CAPGO_TOKEN}" if [ -z "$CAPGO_TOKEN" ]; then echo "CAPGO_TOKEN is not set" exit 1 fi displayName: 'Verify Capgo token' env: CAPGO_TOKEN: $(CAPGO_TOKEN)无法找到构建产物:
# List available artifacts for debugging- script: | ls -la $(System.ArtifactsDirectory) find $(System.ArtifactsDirectory) -name "*.js" -o -name "*.html" displayName: 'Debug artifacts'调试管道
调试管道添加调试步骤来解决问题:
- script: | echo "Build.SourceBranch: $(Build.SourceBranch)" echo "Build.BuildNumber: $(Build.BuildNumber)" echo "Target Channel: $(targetChannel)" displayName: 'Debug Pipeline Variables'
- script: | npx @capgo/cli app debug --apikey $(CAPGO_TOKEN) displayName: 'Debug Capgo App Status'下一步骤
名为“下一步骤”的部分通过 Azure DevOps 集成,您可以自动化您的 Capgo 部署并确保您的移动应用用户接收到一致可靠的更新。
从 Azure DevOps Integration 中继续
标题:从 Azure DevOps Integration 中继续如果您正在使用 Azure DevOps Integration 来规划 CI/CD 自动化,连接它与 Capgo CI/CD 用于 Capgo CI/CD 的产品工作流程 Capgo 原生构建 为产品工作流程在 Capgo 原生构建中 Capgo 集成 为产品工作流程在 Capgo 集成中 CI/CD 集成 CI/CD 集成的实现细节 GitHub 动作集成 在 GitHub 动作集成的实现细节中