Integrasi Azure DevOps
Copy prompt setup berisi langkah install dan panduan markdown lengkap untuk plugin ini.
Integrasikan Capgo Live Updates dengan Azure DevOps Pipelines untuk deploy update aplikasi secara otomatis setiap kali Anda push code. Panduan ini membahas cara setup workflow build, testing, dan deployment otomatis.
Prerequisites
Bagian berjudul “Prasyarat”Sebelum mengatur integrasi Azure DevOps, pastikan Anda sudah memiliki:
- Organisasi dan proyek Azure DevOps
- Akun Capgo dengan aplikasi yang sudah dikonfigurasi
- code source code aplikasi Anda di repositori Azure Repos Git
- Node.js dan npm/yarn yang terkonfigurasi di proyek Anda
Konfigurasi Azure DevOps Pipeline
Bagian berjudul “Setting Up Azure DevOps Pipeline”Langkah 1: Buat Variabel Pipeline
Bagian berjudul “Step 1: Create Pipeline Variables”Pertama, siapkan variabel yang diperlukan di proyek Azure DevOps Anda:
- Buka proyek Azure DevOps Anda
- Buka Pipelines → Library → Grup variabel
- Buat variable group baru bernama
Capgo-Variables - Tambahkan variabel berikut:
| Nama variabel | Nilai | Secure |
|---|---|---|
CAPGO_TOKEN | Token Capgo API Anda | ✅ Ya |
Sederhana
Bagian berjudul “Simple”Konfigurasi dasar yang deploy ke production setiap kali push ke branch main:
# 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'Lanjutan
Bagian berjudul “Advanced”Deployment Feature Branch
Bagian berjudul “Deployment Feature Branch”Deploy feature branch ke test channel untuk review dan testing:
# 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 add $CHANNEL_NAME --apikey $(CAPGO_TOKEN) || true npx @capgo/cli bundle upload --apikey $(CAPGO_TOKEN) --channel $CHANNEL_NAME displayName: 'Deploy to Feature Channel'Menggunakan Enkripsi
Bagian berjudul “Menggunakan Enkripsi”Jika Anda menggunakan fitur enkripsi Capgo, Anda perlu menyimpan private key secara aman di lingkungan CI/CD Anda.
Setelah mengatur encryption keys secara lokal, tambahkan private key Anda ke variabel Azure DevOps:
# Display your private key content (copy this output)cat .capgo_key_v2Tambahkan konten ini sebagai CAPGO_PRIVATE_KEY di variable group Azure DevOps Anda (tandai sebagai secret), lalu gunakan di pipeline:
# 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'Konfigurasi Multi-Channel
Bagian berjudul “Multi-Channel Configuration”Untuk informasi lengkap mengenai setup dan pengelolaan banyak deployment channel, lihat dokumentasi Channels.
Konfigurasi lengkap dengan banyak environment dan deployment pull request:
# 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 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'Deployment Multi-Environment
Bagian berjudul “Multi-Environment Deployment”Untuk skenario kompleks dengan banyak environment:
# 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'Template Deployment (deploy-steps.yml)
Bagian berjudul “Deployment Template (deploy-steps.yml)”Buat file template yang reusable 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 }})'Strategi Deployment Berbasis Branch
Bagian berjudul “Branch-Based Deployment Strategy”Konfigurasi strategi deployment berbeda berdasarkan branch 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)'Best Practice Keamanan
Bagian berjudul “Security Best Practices”Manajemen Variabel yang Aman
Bagian berjudul “Manajemen Variabel yang Aman”- Gunakan Variable Groups: Simpan data sensitif di Azure DevOps variable groups
- Tandai sebagai Secret: Selalu tandai token dan key API sebagai variabel secret
- Batasi Akses: Batasi akses variable group ke pipeline dan user tertentu
- Rotasi Key: Lakukan rotasi rutin pada Capgo API token Anda
Monitoring dan Notifikasi
Bagian berjudul “Monitoring dan Notifikasi”Integrasi Teams
Bagian berjudul “Integrasi Teams”Tambahkan notifikasi Microsoft Teams ke pipeline Anda:
- 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'Notifikasi Email
Bagian berjudul “Notifikasi Email”Konfigurasi notifikasi email untuk status deployment:
- 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)Pemecahan Masalah
Bagian berjudul “Troubleshooting”Masalah Umum
Bagian berjudul “Masalah Umum”Pipeline gagal dengan pesan “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'Error autentikasi:
# 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)Build artifacts tidak ditemukan:
# List available artifacts for debugging- script: | ls -la $(System.ArtifactsDirectory) find $(System.ArtifactsDirectory) -name "*.js" -o -name "*.html" displayName: 'Debug artifacts'Debug Pipeline
Bagian berjudul “Debug Pipeline”Tambahkan langkah debugging untuk menelusuri masalah:
- 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'Next Steps
Bagian berjudul “Langkah Selanjutnya”- Pelajari tentang Channel untuk mengelola berbagai environment deployment
- Jelajahi Penyimpanan Kustom untuk skenario deployment tingkat lanjut
- Setup Enkripsi untuk deployment yang aman
- Konfigurasi Perilaku Update untuk menyesuaikan cara update diterapkan
Dengan integrasi Azure DevOps, Anda dapat mengotomatiskan deployment Capgo dan memastikan update yang konsisten serta andal bagi pengguna aplikasi mobile Anda.
Lanjutkan dari Integrasi Azure DevOps
Bagian berjudul “Lanjutkan dari Integrasi Azure DevOps”Jika Anda menggunakan Integrasi Azure DevOps untuk merencanakan otomatisasi CI/CD, hubungkan dengan Capgo CI/CD untuk alur kerja produk di Capgo CI/CD, Capgo Native Build untuk alur kerja produk di Capgo Native Builds, Integrasi Capgo untuk alur kerja produk di Integrasi Capgo, Integrasi CI/CD untuk detail implementasi di Integrasi CI/CD, dan Integrasi GitHub Actions untuk detail implementasi di Integrasi GitHub Actions.