Integrasi Azure DevOps
Copy sebuah prompt pengaturan dengan langkah instalasi dan panduan markdown lengkap untuk plugin ini.
Integrasikan Capgo Live Updates dengan Pipa Integrasi Azure DevOps untuk mendeploykan secara otomatis pembaruan aplikasi Anda setiap kali Anda mendorong code perubahan. Petunjuk ini mencakup pengaturan pembangunan otomatis, pengujian, dan alur kerja pengiriman.
Prasyarat
Bab berjudul “Prasyarat”Sebelum mengatur integrasi Azure DevOps, pastikan Anda memiliki:
- Organisasi dan proyek Azure DevOps
- Akun Capgo dengan aplikasi yang dikonfigurasi
- Sumber code aplikasi Anda di repositori Git Azure Repos
- Node.js dan npm/yarn yang dikonfigurasi di proyek Anda
Mengatur Azure DevOps Pipeline
Bab yang berjudul “Mengatur Azure DevOps Pipeline”Langkah 1: Buat Variabel Pipeline
Bab yang berjudul “Langkah 1: Buat Variabel Pipeline”Pertama-tama, atur variabel-variabel yang diperlukan di proyek Azure DevOps Anda:
- Navigasikan ke proyek Azure DevOps Anda
- Pergi ke Pipelines → Perpustakaan → Kelompok variabel
- Buat kelompok variabel baru dengan nama
Capgo-Variables - Tambahkan variabel-variabel berikut:
| Nama Variabel | Nilai | Aman |
|---|---|---|
CAPGO_TOKEN | Token Anda Capgo API | ✅ Ya |
Konfigurasi dasar yang mengirimkan ke produksi setiap kali push ke cabang utama:
# 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'Pengiriman Cabang Fitur
Bagian berjudul “Pengiriman Cabang Fitur”Kirimkan cabang fitur ke saluran uji untuk tinjauan dan pengujian:
# 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'Menggunakan Enkripsi
Bab berjudul “Menggunakan Enkripsi”Jika Anda menggunakan Capgo’s fitur enkripsi, Anda akan perlu menyimpan kunci pribadi Anda dengan aman di lingkungan CI/CD Anda.
Setelah mengatur kunci enkripsi secara lokal tambahkan kunci pribadi Anda ke variabel Azure DevOps:
# Display your private key content (copy this output)cat .capgo_key_v2Tambahkan konten ini sebagai CAPGO_PRIVATE_KEY di grup variabel Azure DevOps (tandai sebagai rahasia), kemudian 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-Kanal
Bagian berjudul “Konfigurasi Multi-Kanal”Untuk informasi yang lebih komprehensif tentang pengaturan dan pengelolaan beberapa saluran pengiriman, lihat dokumentasi Dokumentasi Saluran.
Konfigurasi lengkap dengan beberapa lingkungan dan pengiriman permintaan pull:
# 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'Pengiriman Multi-Lingkungan
Bagian berjudul “Pengiriman Multi-Lingkungan”Untuk skenario kompleks dengan beberapa lingkungan:
# 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 Pengiriman (deploy-steps.yml)
Bagian berjudul “Template Pengiriman (deploy-steps.yml)”Buat file template yang dapat digunakan kembali 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 Deploymen Berdasarkan Cabang
Judul Bagian “Strategi Deploymen Berdasarkan Cabang”Konfigurasi strategi deploymen yang berbeda berdasarkan cabang 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)'Praktik Terbaik Keamanan
Judul Bagian “Praktik Terbaik Keamanan”Pengelolaan Variabel yang Aman
Judul Bagian “Pengelolaan Variabel yang Aman”- Gunakan Kelompok VariabelSimpan data sensitif di kelompok variabel Azure DevOps
- Tandai sebagai Rahasia: Selalu tandai token dan kunci API sebagai variabel rahasia
- Akses Lingkungan: Batasi akses grup variabel ke pipeline dan pengguna tertentu
- Rotasi Kunci: Rotasikan secara teratur token dan kunci Capgo API
Pengawasan dan Pemberitahuan
Bab berjudul “Pengawasan dan Pemberitahuan”Pengintegrasian Tim
Bab berjudul “Pengintegrasian Tim”Tambahkan pemberitahuan 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'Pemberitahuan Email
Bagian berjudul “Pemberitahuan Email”Konfigurasi pemberitahuan email untuk status pengembangan:
- 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)Pengaturan Perbaikan
Bagian berjudul “Pengaturan Perbaikan”Masalah Umum
Bagian berjudul “Masalah Umum”Pipelain gagal dengan “Capgo CLI tidak ditemukan”:
# Ensure global installation- script: | npm install -g @capgo/cli which capgo || echo "Capgo CLI not found in PATH" displayName: 'Install and verify Capgo CLI'Gagal 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)Arsip Pembangunan Tidak Ditemukan:
# List available artifacts for debugging- script: | ls -la $(System.ArtifactsDirectory) find $(System.ArtifactsDirectory) -name "*.js" -o -name "*.html" displayName: 'Debug artifacts'Pipeliner Debug
Judul Bagian “Pipeliner Debug”Tambahkan langkah debugging untuk menyelesaikan 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'Langkah-Langkah Selanjutnya
Judul Bagian “Langkah-Langkah Selanjutnya”- Pelajari tentang Saluran untuk mengelola berbagai lingkungan pengembangan
- Eksplorasi Penyimpanan Kustom untuk skenario penggunaan lanjutan
- Konfigurasi Enkripsi untuk penggunaan yang lebih aman
- Konfigurasi Pengaturan Perilaku Pembaruan untuk mengatur bagaimana pembaruan diterapkan
Dengan integrasi Azure DevOps, Anda dapat mengotomasi Capgo Anda dan memastikan pembaruan yang konsisten dan dapat diandalkan untuk pengguna aplikasi seluler Anda.
Lanjutkan dari Integrasi Azure DevOps
Judul bagian “Lanjutkan dari Integrasi Azure DevOps”Jika Anda menggunakan Integrasi Azure DevOps untuk merencanakan otomatisasi CI/CD, hubungkannya dengan Capgo Otomatisasi CI/CD untuk alur kerja produk di Capgo Otomatisasi CI/CD, Capgo Pembangunan Natively untuk alur kerja produk di Capgo Pembangunan Natively, Capgo Integrasi untuk alur kerja produk di Capgo Integrasi, Integrasi CI/CD untuk detail implementasi di Integrasi CI/CD, dan GitHub Integrasi Aksi untuk detail implementasi di GitHub Integrasi Aksi.