Integrasi Bitbucket Pipelines
Salin prompt setup yang berisi langkah install dan panduan markdown lengkap untuk plugin ini.
Integrasikan Capgo Live Updates dengan Bitbucket Pipelines untuk deploy update aplikasi secara otomatis setiap kali Anda push code. Panduan ini mencakup setup automated build, testing, dan workflow deployment.
Prerequisites
Bagian berjudul “Prasyarat”Sebelum setup integrasi Bitbucket Pipelines, pastikan Anda sudah memiliki:
- Akun Bitbucket dengan repository
- Akun Capgo dengan aplikasi yang sudah dikonfigurasi
- Node.js dan npm/yarn yang terkonfigurasi di proyek Anda
Setup Bitbucket Pipelines
Bagian berjudul “Setting Up Bitbucket Pipelines”Langkah 1: Konfigurasi Variabel Repositori
Bagian berjudul “Langkah 1: Konfigurasi Variabel Repositori”Pertama, atur variabel yang diperlukan di repositori Bitbucket Anda:
- Buka repositori Bitbucket Anda
- Buka Pengaturan repositori → Pipelines → Variabel repositori
- Tambahkan variabel berikut:
| Nama variabel | Nilai | Secured |
|---|---|---|
CAPGO_TOKEN | Token Capgo API Anda | ✅ Ya |
Sederhana
Bagian berjudul “Sederhana”Konfigurasi dasar yang deploy ke production setiap kali push ke branch main:
# bitbucket-pipelines.yml - Simple Configurationimage: node:22
pipelines: branches: main: - step: name: Build and Deploy to Production script: - npm ci - npm run test - npm run build - npm install -g @capgo/cli - npx @capgo/cli bundle upload --apikey $CAPGO_TOKEN --channel production artifacts: - dist/**Lanjutan
Bagian berjudul “Lanjutan”Deploy Feature Branch
Bagian berjudul “Deploy Feature Branch”Deploy feature branch ke test channel untuk review dan testing:
# Feature branch deploymentpipelines: branches: feature/*: - step: name: Deploy Feature Branch script: - npm ci - npm run test - npm run build - BRANCH_NAME=$(echo $BITBUCKET_BRANCH | 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 artifacts: - dist/**Menggunakan Enkripsi
Bagian berjudul “Menggunakan Enkripsi”Jika Anda menggunakan Fitur enkripsi Capgo, Anda perlu menyimpan private key dengan aman di lingkungan CI/CD Anda.
Setelah menyiapkan kunci enkripsi secara lokal, tambahkan private key Anda ke variabel Bitbucket:
# Display your private key content (copy this output)cat .capgo_key_v2Tambahkan konten ini sebagai CAPGO_PRIVATE_KEY di variabel repositori Bitbucket Anda (tandai sebagai secured), lalu gunakan di pipeline:
# Deploy with encryption- step: name: Deploy to Capgo with Encryption script: - npm install -g @capgo/cli - npx @capgo/cli bundle upload --apikey $CAPGO_TOKEN --key-data-v2 "$CAPGO_PRIVATE_KEY" --channel productionKonfigurasi Multi-Channel
Bagian berjudul “Konfigurasi Multi-Channel”Untuk informasi lengkap tentang menyiapkan dan mengelola beberapa channel deployment, lihat dokumentasi Channels.
Konfigurasi lengkap dengan beberapa environment dan deployment pull request:
# bitbucket-pipelines.yml - Advanced Multi-Channel Configurationimage: node:22
definitions: steps: - step: &build-step name: Build Application script: - npm ci - npm run test - npm run build artifacts: - dist/**
- step: &deploy-step name: Deploy to Capgo script: - npm install -g @capgo/cli - npx @capgo/cli bundle upload --apikey $CAPGO_TOKEN --channel $CHANNEL_NAME
pipelines: branches: main: - step: <<: *build-step - step: <<: *deploy-step name: Deploy to Production deployment: production trigger: manual script: - export CHANNEL_NAME=production - npm install -g @capgo/cli - npx @capgo/cli bundle upload --apikey $CAPGO_TOKEN --channel $CHANNEL_NAME
develop: - step: <<: *build-step - step: <<: *deploy-step name: Deploy to Development deployment: development script: - export CHANNEL_NAME=development - npm install -g @capgo/cli - npx @capgo/cli bundle upload --apikey $CAPGO_TOKEN --channel $CHANNEL_NAME
pull-requests: '**': - step: <<: *build-step - step: name: Deploy PR to Test Channel script: - CHANNEL_NAME="pr-$BITBUCKET_PR_ID" - 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 artifacts: - dist/**Pipeline Multi-Environment
Bagian berjudul “Pipeline Multi-Environment”Untuk skenario deployment kompleks dengan environment staging dan production:
# Multi-environment pipelineimage: node:22
pipelines: branches: main: - step: name: Build script: - npm ci - npm run test - npm run build artifacts: - dist/** - step: name: Deploy to Staging deployment: staging script: - npm install -g @capgo/cli - npx @capgo/cli bundle upload --apikey $CAPGO_TOKEN --channel staging - step: name: Deploy to Production deployment: production trigger: manual script: - npm install -g @capgo/cli - npx @capgo/cli bundle upload --apikey $CAPGO_TOKEN --channel production
develop: - step: name: Build and Deploy to Development script: - npm ci - npm run test - npm run build - npm install -g @capgo/cli - npx @capgo/cli bundle upload --apikey $CAPGO_TOKEN --channel development artifacts: - dist/**Strategi Deployment Berbasis Branch
Bagian berjudul “Strategi Deployment Berbasis Branch”Deploy berbagai branch secara otomatis ke channel yang sesuai:
# Dynamic channel deploymentimage: node:22
definitions: scripts: - script: &determine-channel | if [ "$BITBUCKET_BRANCH" = "main" ]; then export CHANNEL_NAME="production" elif [ "$BITBUCKET_BRANCH" = "develop" ]; then export CHANNEL_NAME="staging" else export CHANNEL_NAME="development" fi echo "Deploying to channel: $CHANNEL_NAME"
pipelines: default: - step: name: Build and Deploy script: - npm ci - npm run test - npm run build - *determine-channel - npm install -g @capgo/cli - npx @capgo/cli bundle upload --apikey $CAPGO_TOKEN --channel $CHANNEL_NAME artifacts: - dist/**Eksekusi Pipeline Paralel
Bagian berjudul “Eksekusi Pipeline Paralel”Optimalkan waktu build dengan langkah paralel:
# Parallel execution pipelineimage: node:22
pipelines: branches: main: - parallel: - step: name: Run Tests script: - npm ci - npm run test - step: name: Lint Code script: - npm ci - npm run lint - step: name: Build Application script: - npm ci - npm run build artifacts: - dist/** - step: name: Deploy to Production deployment: production script: - npm install -g @capgo/cli - npx @capgo/cli bundle upload --apikey $CAPGO_TOKEN --channel productionPraktik Terbaik Keamanan
Bagian berjudul “Praktik Terbaik Keamanan”Variabel Repositori
Bagian berjudul “Variabel Repositori”- Variabel Terlindungi: Selalu tandai token API sebagai terlindungi
- Variabel Environment: Gunakan variabel spesifik deployment jika diperlukan
- Kontrol Akses: Batasi akses repositori ke anggota tim yang berwenang
- Rotasi Token: Rotasi token Capgo API Anda secara rutin
Lingkungan Deployment
Bagian berjudul “Lingkungan Deployment”Konfigurasikan lingkungan deployment untuk keamanan yang lebih baik:
# Deployment with environment restrictionspipelines: branches: main: - step: name: Deploy to Production deployment: production trigger: manual script: - npm install -g @capgo/cli - npx @capgo/cli bundle upload --apikey $CAPGO_TOKEN --channel productionMonitoring dan Notifikasi
Bagian berjudul “Monitoring dan Notifikasi”Integrasi Slack
Bagian berjudul “Integrasi Slack”Tambahkan notifikasi Slack ke pipeline Anda:
# Pipeline with Slack notificationspipelines: branches: main: - step: name: Build and Deploy script: - npm ci - npm run test - npm run build - npm install -g @capgo/cli - npx @capgo/cli bundle upload --apikey $CAPGO_TOKEN --channel production after-script: - | if [ $BITBUCKET_EXIT_CODE -eq 0 ]; then curl -X POST -H 'Content-type: application/json' \ --data '{"text":"✅ Capgo deployment successful for '$BITBUCKET_BRANCH'"}' \ $SLACK_WEBHOOK_URL else curl -X POST -H 'Content-type: application/json' \ --data '{"text":"❌ Capgo deployment failed for '$BITBUCKET_BRANCH'"}' \ $SLACK_WEBHOOK_URL fiNotifikasi Email
Bagian berjudul “Notifikasi Email”Konfigurasikan notifikasi email melalui fitur bawaan Bitbucket atau gunakan layanan eksternal:
# Email notification step- step: name: Send Notification script: - | curl -X POST \ -H "Content-Type: application/json" \ -d '{ "to": "team@yourcompany.com", "subject": "Capgo Deployment Status", "body": "Deployment of '$BITBUCKET_BRANCH' completed with status: '$BITBUCKET_EXIT_CODE'" }' \ $EMAIL_SERVICE_URL condition: result: [successful, failed]Pemecahan Masalah
Bagian berjudul “Troubleshooting”Masalah Umum
Bagian berjudul “Masalah Umum”Pipeline gagal dengan pesan “Capgo CLI not found”:
# Debug CLI installation- step: name: Debug CLI script: - npm install -g @capgo/cli - which capgo || echo "Capgo CLI not found" - npx @capgo/cli --versionError autentikasi:
# Verify token configuration- step: name: Debug Auth script: - | if [ -z "$CAPGO_TOKEN" ]; then echo "CAPGO_TOKEN is not set" exit 1 fi echo "Token length: ${#CAPGO_TOKEN}"Build artifacts tidak ditemukan:
# List build outputs- step: name: Debug Build script: - ls -la dist/ - find dist/ -type f -name "*.js" -o -name "*.html"Debug Pipeline
Bagian berjudul “Debug Pipeline”Tambahkan informasi debugging untuk troubleshooting masalah:
# Debug pipelinepipelines: branches: main: - step: name: Debug Information script: - echo "Branch: $BITBUCKET_BRANCH" - echo "Commit: $BITBUCKET_COMMIT" - echo "Build: $BITBUCKET_BUILD_NUMBER" - env | grep BITBUCKET_ | sort - step: name: Build and Deploy script: - npm ci - npm run test - npm run build - npm install -g @capgo/cli - npx @capgo/cli bundle upload --apikey $CAPGO_TOKEN --channel productionValidasi Pipeline
Bagian berjudul “Validasi Pipeline”Aktifkan validasi pipeline untuk mendeteksi error konfigurasi:
# Enable pipeline validationoptions: docker: true size: 2x
pipelines: branches: main: - step: name: Validate Pipeline script: - echo "Pipeline validation successful" - step: name: Build and Deploy script: # ... deployment stepsLangkah Berikutnya
Bagian berjudul “Langkah Selanjutnya”- Pelajari tentang Channel untuk mengelola berbagai environment deployment
- Jelajahi Penyimpanan Kustom untuk skenario deployment tingkat lanjut
- Siapkan Enkripsi untuk deployment yang aman
- Konfigurasi Perilaku Update untuk menyesuaikan cara update diterapkan
Dengan integrasi Bitbucket Pipelines, Anda dapat mengotomatiskan deployment Capgo dan memastikan update yang konsisten serta andal bagi pengguna aplikasi mobile Anda.
Lanjutkan dengan Integrasi Bitbucket Pipelines
Bagian berjudul “Lanjutkan dengan Integrasi Bitbucket Pipelines”Jika Anda menggunakan Integrasi Bitbucket Pipelines untuk merencanakan otomatisasi CI/CD, hubungkan dengan CI/CD Capgo untuk workflow produk di Capgo CI/CD, Capgo Native Build untuk workflow 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.