Lompat ke konten

Integrasi Pipelaj Bitbucket

Integrate Capgo Live Updates with Bitbucket Pipelines to automatically deploy your app updates whenever you push code changes. This guide covers setting up automated builds, testing, and deployment workflows.

Sebelum mengatur integrasi Bitbucket Pipelines, pastikan Anda memiliki:

  • Suatu akun Bitbucket dengan repositori
  • Suatu Capgo dengan aplikasi yang telah dikonfigurasi
  • Node.js dan npm/yarn yang telah dikonfigurasi di proyek Anda

Pertama-tama, atur variabel yang diperlukan di repositori Bitbucket Anda:

  1. Navigasi ke repositori Bitbucket Anda
  2. Pergi ke Pengaturan RepositoriPipelinesVariabel Repositori
  3. Tambahkan variabel berikut:
Nama VariabelNilaiDitutupi
CAPGO_TOKENToken Anda Capgo API✅ Ya

Salin ke clipboard

Pengaturan Lanjutan

Bab “Pengaturan Lanjutan”

# bitbucket-pipelines.yml - Simple Configuration
image: 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/**

Bab “Deployan Cabang Fitur”

Section titled “Simple”

Basic configuration that deploys to production on every push to the main branch:

Copy to clipboard

Deploy fitur cabang ke saluran uji untuk tinjauan dan pengujian:

# Feature branch deployment
pipelines:
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/**

Jika Anda menggunakan Capgo’s fitur enkripsi, Anda akan perlu menyimpan kunci pribadi Anda secara aman di lingkungan CI/CD Anda.

Setelah mengatur kunci enkripsi secara lokal, tambahkan kunci pribadi Anda ke variabel Bitbucket: Jendela Terminal

Salin ke clipboard
# Display your private key content (copy this output)
cat .capgo_key_v2

dalam variabel repository Bitbucket Anda (tandai sebagai terenkripsi), lalu gunakan di pipeline: CAPGO_PRIVATE_KEY Salin ke clipboard

# 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 production

Untuk informasi yang lebih komprehensif tentang pengaturan dan pengelolaan beberapa saluran pengiriman, lihatlah Dokumentasi Saluran.

Konfigurasi lengkap dengan beberapa lingkungan dan pengiriman pull request:

# bitbucket-pipelines.yml - Advanced Multi-Channel Configuration
image: 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/**

Untuk skenario pengiriman kompleks dengan lingkungan pengujian dan produksi:

# Multi-environment pipeline
image: 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

Judul Bagian “Strategi Pengiriman Berdasarkan Cabang”

Tetapkan pengiriman cabang yang berbeda ke saluran yang tepat:

# Dynamic channel deployment
image: 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/**

Optimalkan waktu pembangunan dengan langkah-langkah paralel:

# Parallel execution pipeline
image: 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 production
  1. Variabel Terlindungi: Selalu tandai token API sebagai terlindungi
  2. Variabel Lingkungan: Gunakan variabel khusus untuk penggunaan
  3. Kontrol Akses: Batasi akses repositori hanya untuk anggota tim yang berwenang
  4. Penggantian Token: Rotasi secara teratur token Capgo API

Konfigurasi lingkungan pengembangan untuk keamanan yang lebih baik:

# Deployment with environment restrictions
pipelines:
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 production

Tambahkan pemberitahuan Slack ke pipa Anda:

# Pipeline with Slack notifications
pipelines:
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
fi

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]

Pipelain 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 --version

Masalah 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"

Tambahkan informasi debugging untuk menyelesaikan masalah:

# Debug pipeline
pipelines:
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 production

Aktifkan validasi pipa untuk menangkap kesalahan konfigurasi:

# Enable pipeline validation
options:
docker: true
size: 2x
pipelines:
branches:
main:
- step:
name: Validate Pipeline
script:
- echo "Pipeline validation successful"
- step:
name: Build and Deploy
script:
# ... deployment steps
  • Pelajari tentang Saluran untuk mengelola lingkungan pengembangan yang berbeda
  • Eksplor Penyimpanan Kustom untuk skenario penggunaan lanjutan
  • Konfigurasi Enkripsi untuk penggunaan yang lebih aman
  • Konfigurasi Perbarui Pola untuk mengatur bagaimana perbarui diterapkan

Dengan integrasi Pipelines Bitbucket, Anda dapat mengotomatisasi Capgo Anda dan memastikan pembaruan yang konsisten dan dapat diandalkan untuk pengguna aplikasi seluler Anda.

Teruskan dari Integrasi Pipelines Bitbucket

Judul bagian “Teruskan dari Integrasi Pipelines Bitbucket”

Jika Anda menggunakan Integrasi Pipelines Bitbucket 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.