Integrasi Pipelaj Bitbucket
Copas prompt pengaturan dengan langkah instalasi dan panduan markdown lengkap untuk plugin ini.
Integrasikan Capgo Live Updates dengan Bitbucket Pipelines untuk memperbarui aplikasi Anda secara otomatis setiap kali Anda memasukkan code perubahan. Panduan ini menjelaskan pengaturan build otomatis, pengujian, dan alur kerja pengiriman.
Prasyarat
Judul Bagian “Prasyarat”Sebelum mengatur integrasi Bitbucket Pipelines, pastikan Anda memiliki:
- Akun Bitbucket dengan repositori
- Akun Capgo dengan aplikasi yang telah dikonfigurasi
- Node.js dan npm/yarn telah dikonfigurasi di proyek Anda
Pengaturan Bitbucket Pipelines
Bab yang berjudul “Pengaturan Bitbucket Pipelines”Langkah 1: Konfigurasi Variabel Repositori
Bab yang berjudul “Langkah 1: Konfigurasi Variabel Repositori”Pertama-tama, atur variabel-variabel yang diperlukan di repositori Bitbucket Anda:
- Navigasikan ke repositori Bitbucket Anda
- Pergi ke Pengaturan Repositori → Pipelines → Variabel Repositori
- Tambahkan variabel-variabel berikut:
| Nama Variabel | Nilai | Ditambahkan Keamanan |
|---|---|---|
CAPGO_TOKEN | Token Anda Capgo API | ✅ Ya |
Sederhana
Bagian berjudul “Sederhana”Konfigurasi dasar yang mengirimkan ke produksi setiap kali push ke cabang utama:
# 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/**Pengiriman Cabang Fitur
Bagian berjudul “Pengiriman Cabang Fitur”Kirimkan cabang fitur ke saluran uji untuk tinjauan dan pengujian:
# 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 create $CHANNEL_NAME --apikey $CAPGO_TOKEN || true - npx @capgo/cli bundle upload --apikey $CAPGO_TOKEN --channel $CHANNEL_NAME artifacts: - dist/**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 Bitbucket:
# Display your private key content (copy this output)cat .capgo_key_v2Tambahkan konten ini sebagai CAPGO_PRIVATE_KEY di repository variabel Bitbucket Anda (tandai sebagai terlindungi), kemudian 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 yang lebih komprehensif tentang pengaturan dan pengelolaan saluran-deployment yang banyak, lihat dokumen Dokumentasi Saluran.
Konfigurasi lengkap dengan beberapa lingkungan dan pengiriman permintaan pull:
# 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 create $CHANNEL_NAME --apikey $CAPGO_TOKEN || true - npx @capgo/cli bundle upload --apikey $CAPGO_TOKEN --channel $CHANNEL_NAME artifacts: - dist/**Pipeliner Lingkungan Multi
Bagian berjudul “Pipeliner Lingkungan Multi”Untuk skenario-deployment kompleks dengan lingkungan pengujian dan produksi:
# 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 Pengiriman Berdasarkan Cabang
Bagian berjudul “Strategi Pengiriman Berdasarkan Cabang”Tetapkan otomatis cabang yang berbeda ke saluran yang tepat:
# 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 Pipa Paralel Sama Waktu
Judul Bagian “Eksekusi Pipa Paralel Sama Waktu”Optimalkan waktu pembangunan dengan langkah-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
Judul Bagian “Praktik Terbaik Keamanan”Variabel Repositori
Judul Bagian “Variabel Repositori”- Variabel TerlindungiSelalu tandai token API sebagai terlindungi
- Variabel LingkunganGunakan variabel khusus penggunaan saat dibutuhkan
- Akses Kontrol : Batasi akses repositori untuk anggota tim yang diotorisasi
- Rotasi Token : Rotasikan secara teratur Capgo API token Anda
Lingkungan Pengembangan
Bagian berjudul “Lingkungan Pengembangan”Konfigurasi lingkungan pengembangan 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 productionPengawasan dan Pemberitahuan
Bagian berjudul “Pengawasan dan Pemberitahuan”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 fiPemberitahuan Email
Judul bagian “Pemberitahuan Email”Konfigurasi pemberitahuan email melalui fitur bawaan Bitbucket atau menggunakan 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]Pengaturan Masalah
Judul bagian “Pengaturan Masalah”Masalah Umum
Judul bagian “Masalah Umum”Pipeline gagal dengan “Capgo CLI tidak ditemukan”:
# 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}"Tidak ditemukan artefak pembangunan:
# List build outputs- step: name: Debug 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 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 Pipelaj
Bagian berjudul “Validasi Pipelaj”Aktifkan validasi pipelaj untuk menangkap kesalahan 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-Langkah Berikutnya
Judul Bagian 'Langkah-Langkah Berikutnya'- Pelajari tentang Saluran untuk mengelola berbagai lingkungan pengembangan
- Eksplorasi Penyimpanan Kustom untuk skenario pengembangan maju
- Tetapkan Enkripsi untuk pengembangan yang aman
- Konfigurasi Perbarui perilaku untuk mengatur bagaimana perbaruan diterapkan
Dengan integrasi Bitbucket Pipelines, Anda dapat otomatisasi Capgo Anda dan memastikan perbaruan yang konsisten dan dapat diandalkan untuk pengguna aplikasi mobile Anda.
Lanjutkan dari Integrasi Bitbucket Pipelines
Judul bagian “Lanjutkan dari Integrasi Bitbucket Pipelines”Jika Anda menggunakan Integrasi Bitbucket Pipelines untuk merencanakan otomatisasi CI/CD, hubungkannya dengan Capgo CI/CD untuk alur kerja produk di Capgo CI/CD, Capgo Pembangunan Natively untuk alur kerja produk di Capgo Pembangunan Natively, Integrasi Capgo Untuk alur kerja produk dalam Integrasi Capgo, Integrasi CI/CD Untuk detail implementasi dalam Integrasi CI/CD, dan Integrasi Aksi GitHub Untuk detail implementasi dalam Integrasi Aksi GitHub.