Integrasi GitLab CI/CD
Copas prompt pengaturan dengan langkah instalasi dan panduan markdown lengkap untuk plugin ini.
Integrate Capgo Live Updates with GitLab CI/CD to automatically deploy your app updates whenever you push code changes. This guide covers setting up automated builds, testing, and deployment workflows.
Persyaratan sebelum mengatur
Bagian berjudul “Persyaratan’Sebelum mengatur integrasi GitLab CI/CD, pastikan Anda memiliki:
- Akun GitLab dengan repositori proyek
- Akun Capgo dengan aplikasi yang telah dikonfigurasi
- Node.js dan npm/yarn yang telah dikonfigurasi di proyek Anda
Mengatur GitLab CI/CD
Bagian berjudul “Mengatur GitLab CI/CD’Langkah 1: Konfigurasi Variabel Lingkungan
Bagian berjudul “Langkah 1: Konfigurasi Variabel Lingkungan’Pertama-tama, atur variabel yang diperlukan di proyek GitLab Anda:
- Navigasi ke proyek GitLab Anda
- Pergi ke Pengaturan → CI/CD → Variabel
- Tambahkan variabel berikut:
| Nama Variabel | Nilai | Dilindungi | Tersembunyi |
|---|---|---|---|
CAPGO_TOKEN | Token Anda Capgo API | ✅ Ya | ✅ Ya |
Salin ke clipboard
Menggunakan cabang fiturBagian berjudul “Menggunakan cabang fitur”
# .gitlab-ci.yml - Simple Configurationimage: node:22
stages: - build - deploy
variables: npm_config_cache: "$CI_PROJECT_DIR/.npm"
build: stage: build script: - npm ci - npm run test - npm run build artifacts: paths: - dist/ expire_in: 1 hour only: - main
deploy_production: stage: deploy script: - npm install -g @capgo/cli - npx @capgo/cli bundle upload --apikey $CAPGO_TOKEN --channel production # For encrypted uploads, add: --key-data-v2 "$CAPGO_PRIVATE_KEY" dependencies: - build only: - mainSalin ke clipboard
Konfigurasi lanjutanBagian berjudul “Konfigurasi lanjutan”
Bagian berjudul “Pengiriman Cabang Fitur”Tingkatkan cabang fitur untuk saluran uji untuk tinjauan dan pengujian:
# Feature branch deploymentdeploy_feature: stage: deploy script: - npm install -g @capgo/cli - CHANNEL_NAME="feature-$(echo $CI_COMMIT_REF_NAME | sed 's/[^a-zA-Z0-9-]/-/g')" - npx @capgo/cli channel create $CHANNEL_NAME --apikey $CAPGO_TOKEN || true - npx @capgo/cli bundle upload --apikey $CAPGO_TOKEN --channel $CHANNEL_NAME dependencies: - build only: - /^feature\/.*$/ environment: name: feature/$CI_COMMIT_REF_NAME url: https://your-app.com/channels/$CHANNEL_NAMEMenggunakan Enkripsi
Bagian berjudul “Menggunakan Enkripsi”Jika Anda menggunakan fitur enkripsi dari __CAPGO_KEEP_0__ Capgo’s encryption feature, Anda perlu menyimpan kunci pribadi Anda dengan aman di lingkungan CI/CD Anda.
Setelah mengatur kunci enkripsi di lokal, tambahkan kunci pribadi Anda ke variabel GitLab:
# Display your private key content (copy this output)cat .capgo_key_v2Tambahkan konten ini sebagai CAPGO_PRIVATE_KEY di variabel proyek GitLab Anda (tandai sebagai terlindungi dan tersembunyi), lalu gunakan di pipeline:
# Deploy with encryptiondeploy_production: script: - npm install -g @capgo/cli - npx @capgo/cli bundle upload --apikey $CAPGO_TOKEN --key-data-v2 "$CAPGO_PRIVATE_KEY" --channel productionUntuk informasi yang lebih komprehensif tentang pengaturan dan pengelolaan saluran pengiriman yang berbeda, lihat dokumentasi
Saluran DokumentasiKonfigurasi lengkap dengan beberapa lingkungan dan pengiriman permintaan gabungan: Salin ke clipboard.
Multi-Lingkungan dengan Persetujuan Tangan
# .gitlab-ci.yml - Advanced Multi-Channel Configurationimage: node:22
stages: - build - deploy
variables: npm_config_cache: "$CI_PROJECT_DIR/.npm"
# Build stagebuild: stage: build script: - npm ci - npm run test - npm run build artifacts: paths: - dist/ expire_in: 24 hours
# Deploy to development channeldeploy_development: stage: deploy script: - npm install -g @capgo/cli - npx @capgo/cli bundle upload --apikey $CAPGO_TOKEN --channel development dependencies: - build only: - develop environment: name: development
# Deploy merge requests to test channelsdeploy_mr: stage: deploy script: - npm install -g @capgo/cli - CHANNEL_NAME="mr-$CI_MERGE_REQUEST_IID" - npx @capgo/cli channel create $CHANNEL_NAME --apikey $CAPGO_TOKEN || true - npx @capgo/cli bundle upload --apikey $CAPGO_TOKEN --channel $CHANNEL_NAME dependencies: - build only: - merge_requests environment: name: review/$CI_MERGE_REQUEST_IID url: https://your-app.com/channels/mr-$CI_MERGE_REQUEST_IID on_stop: cleanup_mr
# Cleanup MR channels when MR is closedcleanup_mr: stage: deploy script: - npm install -g @capgo/cli - npx @capgo/cli channel delete mr-$CI_MERGE_REQUEST_IID --apikey $CAPGO_TOKEN || true when: manual environment: name: review/$CI_MERGE_REQUEST_IID action: stop only: - merge_requests
# Deploy to stagingdeploy_staging: stage: deploy script: - npm install -g @capgo/cli - npx @capgo/cli bundle upload --apikey $CAPGO_TOKEN --channel staging dependencies: - build only: - develop environment: name: staging
# Deploy to productiondeploy_production: stage: deploy script: - npm install -g @capgo/cli - npx @capgo/cli bundle upload --apikey $CAPGO_TOKEN --channel production dependencies: - build only: - main environment: name: productionUntuk informasi yang lebih komprehensif tentang pengaturan dan pengelolaan saluran pengiriman yang berbeda, lihat dokumentasi
Saluran DokumentasiUntuk penggunaan produksi yang memerlukan persetujuan manual:
deploy_production: stage: deploy script: - npm install -g @capgo/cli - npx @capgo/cli bundle upload --apikey $CAPGO_TOKEN --channel production dependencies: - build only: - main when: manual environment: name: productionStrategi Pengembangan Berdasarkan Cabang
Bagian berjudul “Strategi Pengembangan Berdasarkan Cabang”Tunggu hingga cabang yang berbeda diarahkan ke saluran yang tepat secara otomatis:
# Dynamic channel deployment based on branchdeploy: stage: deploy script: - npm install -g @capgo/cli - | if [ "$CI_COMMIT_REF_NAME" = "main" ]; then CHANNEL="production" elif [ "$CI_COMMIT_REF_NAME" = "develop" ]; then CHANNEL="staging" else CHANNEL="development" fi - npx @capgo/cli bundle upload --apikey $CAPGO_TOKEN --channel $CHANNEL dependencies: - build environment: name: $CHANNELPraktik Keamanan Terbaik
Bagian berjudul “Praktik Keamanan Terbaik”Variabel Terlindungi
Bagian berjudul “Variabel Terlindungi”- Tandai Variabel yang SensitiveSelalu tandai token API sebagai terlindungi dan tersembunyi
- Pengaman Cabang: Gunakan variabel terlindungi untuk pengiriman produksi
- Kontrol Akses: Batasi akses variabel hanya untuk pemelihara
- Rotasi Teratur: Rotasi API secara teratur
Konfigurasi Pipa yang Aman
Bagian berjudul “Konfigurasi Pipa yang Aman”# Use protected variables for productiondeploy_production: stage: deploy script: - npm install -g @capgo/cli - npx @capgo/cli bundle upload --apikey $CAPGO_TOKEN --channel production only: refs: - main variables: - $CI_COMMIT_REF_PROTECTED == "true"Pengawasan dan Pemberitahuan
Bagian berjudul “Pengawasan dan Pemberitahuan”Integrasi Slack
Integrasi SlackTambahkan pemberitahuan Slack ke pipeline Anda:
notify_success: stage: .post image: alpine:latest before_script: - apk add --no-cache curl script: - | curl -X POST -H 'Content-type: application/json' \ --data '{"text":"✅ Capgo deployment successful for '"$CI_COMMIT_REF_NAME"'"}' \ $SLACK_WEBHOOK_URL when: on_success
notify_failure: stage: .post image: alpine:latest before_script: - apk add --no-cache curl script: - | curl -X POST -H 'Content-type: application/json' \ --data '{"text":"❌ Capgo deployment failed for '"$CI_COMMIT_REF_NAME"'"}' \ $SLACK_WEBHOOK_URL when: on_failurePemberitahuan Email
Integrasi EmailKonfigurasi pemberitahuan email di pengaturan proyek GitLab Anda atau gunakan API:
notify_email: stage: .post script: - | curl --request POST \ --header "PRIVATE-TOKEN: $GITLAB_API_TOKEN" \ --form "to=team@yourcompany.com" \ --form "subject=Capgo Deployment Status" \ --form "body=Deployment of $CI_COMMIT_REF_NAME completed with status: $CI_JOB_STATUS" \ "https://gitlab.com/api/v4/projects/$CI_PROJECT_ID/emails" when: alwaysPengaturan Perbaikan
Masalah UmumPipeline fails with “Capgo CLI not found”:
# Debug CLI installationdebug_cli: script: - npm install -g @capgo/cli - which capgo || echo "Capgo CLI not found" - npx @capgo/cli --versionError autentikasi:
# Verify token configurationdebug_auth: script: - | if [ -z "$CAPGO_TOKEN" ]; then echo "CAPGO_TOKEN is not set" exit 1 fi echo "Token length: ${#CAPGO_TOKEN}"Tidak ditemukan artefak pembangunan:
# List build outputsdebug_build: script: - ls -la dist/ - find dist/ -type f -name "*.js" -o -name "*.html"Pipelaj Debug
Bagian berjudul “Pipelaj Debug”Tambahkan informasi debugging untuk menyelesaikan masalah:
debug: stage: build script: - echo "Branch: $CI_COMMIT_REF_NAME" - echo "Commit: $CI_COMMIT_SHA" - echo "Build: $CI_PIPELINE_ID" - env | grep CI_ | sort only: - branchesLangkah-Langkah Selanjutnya
Bagian berjudul “Langkah-Langkah Selanjutnya”- Pelajari tentang Saluran __CAPGO_KEEP_0__ untuk mengelola berbagai lingkungan pengembangan
- Lihat Penyimpanan Kustom untuk skenario pengembangan lanjutan
- Konfigurasi Enkripsi untuk pengembangan yang aman
- Konfigurasi Pengaturan Perbaruan untuk mengatur cara perbaruan diterapkan
Dengan integrasi GitLab CI/CD, Anda dapat mengotomatisasi Capgo Anda dan memastikan perbaruan yang konsisten dan dapat diandalkan untuk pengguna aplikasi mobile Anda.