Zum Inhalt springen

Bitbucket Pipelines-Integration

Integriere Capgo Live Updates mit Bitbucket Pipelines, um Ihre App-Updates automatisch zu deployen, sobald Sie code Änderungen pushen. Diese Anleitung deckt die Einrichtung von automatisierten Builds, Tests und Bereitstellungsworkflows ab.

Bevor Sie die Integration von Bitbucket Pipelines einrichten, stellen Sie sicher, dass Sie Folgendes haben:

  • Ein Bitbucket-Konto mit einem Repository
  • Ein Capgo-Konto mit einer konfigurierten App
  • Node.js und npm/yarn in Ihrem Projekt konfiguriert

Bitbucket Pipelines einrichten

Abschnitt: Bitbucket Pipelines einrichten

Schritt 1: Repository-Variablen konfigurieren

Abschnitt: Schritt 1: Repository-Variablen konfigurieren

Zuerst müssen Sie die notwendigen Variablen in Ihrem Bitbucket-Repository einrichten:

  1. Navigieren Sie zu Ihrem Bitbucket-Repository
  2. Gehe zu Repository-EinstellungenPipelinesRepository-Variablen
  3. Füge die folgenden Variablen hinzu:
VariablennameWertVerschlüsselt
CAPGO_TOKENDein Capgo API-Token✅ Ja

Grundlegende Konfiguration, die auf jeden Push in die Hauptzweig in die Produktion deployt:

# 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/**

Deployen Featurezweige in Testkanälen für Überprüfung und Testen:

# 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/**

Abschnitt mit dem Titel „Mit Verschlüsselung arbeiten“

Wenn Sie die Verschlüsselungsfunktion von __CAPGO_KEEP_0__ verwenden

benötigen Sie Ihren privaten Schlüssel sicher in Ihrem CI/CD-Umgebung zu speichern. Capgo’s encryption feature, you’ll need to store your private key securely in your CI/CD environment.

After der Verschlüsselungsschlüssel lokal eingerichtet haben, fügen Sie Ihren privaten Schlüssel zu den Bitbucket-Variablen hinzu: Terminalfenster Zur Vervollständigung in die Zwischenablage kopieren

Hinzufügen Sie diesen Inhalt als
# Display your private key content (copy this output)
cat .capgo_key_v2

Zur Vervollständigung in die Zwischenablage kopieren CAPGO_PRIVATE_KEY Achtung

# 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

Für umfassende Informationen zum Einrichten und Verwalten mehrerer Bereitstellungskanäle, siehe die Dokumentation zu den Kanälen.

Vollständige Konfiguration mit mehreren Umgebungen und Pull-Request-Bereitstellungen:

# 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/**

Für komplexe Bereitstellungs-Szenarien mit Staging- und Produktionsumgebungen:

# 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/**

Automatisch verschiedene Branches auf die entsprechenden Kanäle bereitstellen:

# 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/**

Optimieren Sie die Buildzeiten mit parallelen Schritten:

# 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. Beschützte Variablen: Markiere immer API-Token als beschützt
  2. Umgebungsvariablen: Verwende deployment-spezifische Variablen wenn nötig
  3. Zugriffssteuerung: Beschränke den Zugriff auf das Repository auf autorisierte Teammitglieder
  4. Tokenrotation: Rotiere deine Capgo- und API-Token regelmäßig

Konfiguriere Deploymentsumgebungen für bessere Sicherheit:

# 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

Fügen Sie Slack-Benachrichtigungen Ihrem Pipeline hinzu:

# 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

Konfigurieren Sie E-Mail-Benachrichtigungen über die integrierten Funktionen von Bitbucket oder mit externen Diensten:

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

Pipeline fehlschlägt mit „Capgo CLI nicht gefunden“:

# Debug CLI installation
- step:
name: Debug CLI
script:
- npm install -g @capgo/cli
- which capgo || echo "Capgo CLI not found"
- npx @capgo/cli --version

Authentifizierungsfehler:

# 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-Artikel nicht gefunden:

# List build outputs
- step:
name: Debug Build
script:
- ls -la dist/
- find dist/ -type f -name "*.js" -o -name "*.html"

Fehlersuche durch Hinzufügen von Debug-Informationen ermöglichen:

# 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

Pipeline-Validierung aktivieren, um Konfigurationsfehler zu erkennen:

# 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

Mit der Integration von Bitbucket Pipelines können Sie Ihre Capgo-Bereitstellungen automatisieren und sicherstellen, dass Ihre mobilen App-Benutzer konsistente und zuverlässige Updates erhalten.

Wenn Sie Bitbucket Pipelines Integration verwenden für die Automatisierung von CI/CD zu planen, mit ihm verbunden Capgo CI/CD für den Produktworkflow in Capgo CI/CD Capgo Native Builds für den Produktworkflow in Capgo Native Builds Capgo Integrations für den Produktworkflow in Capgo Integrations CI/CD-Integration für die Implementierungsdetails in CI/CD-Integration GitHub Actions-Integration für die Implementierungsdetails in GitHub Actions-Integration