メインコンテンツへスキップ

Azure DevOps 連携

Capgo Live Updates を Azure DevOps Pipelines に統合し、code の変更を push するたびにアプリの更新を自動的にデプロイできます。このガイドでは、自動ビルド、テスト、デプロイワークフローのセットアップについて説明します。

Azure DevOps 連携を設定する前に、以下を確認してください:

  • Azure DevOps の組織とプロジェクト
  • アプリが設定済みの Capgo アカウント
  • Azure Repos Git リポジトリ内のアプリのソース code
  • プロジェクトでNode.jsと npm/yarnが設定済みであること

Azure DevOps Pipeline のセットアップ

「Azure DevOps パイプラインの設定」セクション

ステップ 1: パイプライン変数の作成

「ステップ 1: パイプライン変数の作成」セクション

まず、Azure DevOps プロジェクトに必要な変数を設定します:

  1. Azure DevOps プロジェクトに移動します
  2. 以下に移動します: パイプライン → ライブラリ → 変数グループ
  3. 名前のついた新しい変数グループを作成します Capgo-Variables
  4. 以下の変数を追加します:
変数名値セキュア
CAPGO_TOKENCapgo API トークン✅ はい

mainブランチへのpushごとに本番環境へデプロイする基本設定:

# Simple Azure DevOps Pipeline for Capgo Live Updates
trigger:
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 deployment
trigger:
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 add $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環境に安全に保存する必要があります。

完了後、 暗号化キーの設定 ローカルで、秘密鍵を Azure DevOps の変数に追加します:

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

この内容を次のように追加します: CAPGO_PRIVATE_KEY Azure DevOps の変数グループに追加します(シークレットとしてマークし)、パイプラインで使用します:

# 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 Channels
trigger:
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 add $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 environments
parameters:
- 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:

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ブランチに基づいて異なるデプロイ戦略を設定します:

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)'

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

「セキュリティベストプラクティス」セクション
  1. 変数グループの使用:機密データを Azure DevOps の変数グループに保存します
  2. シークレットとしてマーク:API のトークンやキーは、常にシークレット変数としてマークしてください
  3. アクセス範囲の制限:変数グループへのアクセスを特定のパイプラインとユーザーに限定します
  4. キーのローテーション:Capgo API トークンを定期的にローテーションしてください

パイプラインに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 not found」でパイプラインが失敗する場合:

# 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 連携 CI/CD自動化を計画するには、次と連携してください Capgo での CI/CD 設定 Capgo CI/CDでのプロダクトワークフローについては、 Capgo Native Build Capgo Native Buildsでのプロダクトワークフローについては、 Capgo インテグレーション Capgo インテグレーションでのプロダクトワークフロー向けに、 CI/CD 連携 CI/CD Integrationの実装詳細については、 GitHub Actions 連携 GitHub Actions Integrationの実装詳細については。