Zum Inhalt springen

GitLab CI/CD-Integration

Integriere Capgo Live Updates mit GitLab CI/CD, um deine App-Updates automatisch zu deployen, sobald du code Änderungen pushst. Diese Anleitung deckt die Einrichtung von automatischen Builds, Tests und Bereitstellungsworfkäufen ab.

Bevor du die GitLab CI/CD-Integration einrichtest, stelle sicher, dass du hast:

  • Einen GitLab-Account mit einem Projekt-Repository
  • A Capgo-Konto mit einer konfigurierten App
  • Node.js und npm/yarn sind in Ihrem Projekt konfiguriert

Zunächst müssen Sie die notwendigen Variablen in Ihrem GitLab-Projekt einrichten:

  1. Navigieren Sie zu Ihrem GitLab-Projekt
  2. Gehe zu EinstellungenCI/CDVariablen
  3. Fügen Sie die folgenden Variablen hinzu:
VariablennameWertGeschütztVerdeckt
CAPGO_TOKENIhr Capgo API Token✅ Ja✅ Ja

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

# .gitlab-ci.yml - Simple Configuration
image: 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:
- main

Deployen Sie Feature-Zweige in Testkanäle für Überprüfung und Testen:

# Feature branch deployment
deploy_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_NAME

Abschnitt mit dem Titel “Mit Verschlüsselung arbeiten”

Wenn Sie die Verschlüsselungsfunktion von __CAPGO_KEEP_0__ verwenden

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

After setting up encryption keys lokale, fügen Sie Ihre private Schlüssel zu den GitLab Variablen hinzu:

Terminalfenster
# Display your private key content (copy this output)
cat .capgo_key_v2

Fügen Sie diesen Inhalt als CAPGO_PRIVATE_KEY in Ihren GitLab-Projektvariablen (markieren Sie als geschützt und maskiert), dann verwenden Sie ihn in Pipelines:

# Deploy with encryption
deploy_production:
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 zur Einrichtung und Verwaltung mehrerer Bereitstellungskanäle, siehe die Dokumentation zu den Kanälen.

Komplete Konfiguration mit mehreren Umgebungen und Merge-Request-Deployments:

# .gitlab-ci.yml - Advanced Multi-Channel Configuration
image: node:22
stages:
- build
- deploy
variables:
npm_config_cache: "$CI_PROJECT_DIR/.npm"
# Build stage
build:
stage: build
script:
- npm ci
- npm run test
- npm run build
artifacts:
paths:
- dist/
expire_in: 24 hours
# Deploy to development channel
deploy_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 channels
deploy_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 closed
cleanup_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 staging
deploy_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 production
deploy_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: production

Für Produktionsbereitstellungen, die eine manuelle Genehmigung erfordern:

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

Deployen Sie verschiedene Branches automatisch auf die entsprechenden Kanäle:

# Dynamic channel deployment based on branch
deploy:
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: $CHANNEL
  1. Sensiblen Variablen eine Markierung geben: Always mark API tokens as protected and masked
  2. Verwenden Sie geschützte Variablen für ProduktionsbereitstellungenZugriffssteuerung
  3. Markieren Sie __CAPGO_KEEP_0__-Token immer als geschützt und maskiert: Zugriff auf Variablen auf Maintainer beschränken
  4. Regelmäßige Rotation: Rotieren Sie API-Tokens regelmäßig
# Use protected variables for production
deploy_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"

Slack-Benachrichtigungen zu Ihrer Pipeline hinzufügen:

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_failure

E-Mail-Benachrichtigungen

Abschnitt: E-Mail-Benachrichtigungen

Konfigurieren Sie E-Mail-Benachrichtigungen in Ihren GitLab-Projekt-Einstellungen oder verwenden Sie den 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: always

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

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

Authentifizierungsfehler:

# Verify token configuration
debug_auth:
script:
- |
if [ -z "$CAPGO_TOKEN" ]; then
echo "CAPGO_TOKEN is not set"
exit 1
fi
echo "Token length: ${#CAPGO_TOKEN}"

Build artefakte nicht gefunden:

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

Fügen Sie Debugging-Informationen hinzu, um Probleme zu lösen:

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:
- branches

Mit der Integration von GitLab CI/CD können Sie Ihre Capgo-Bereitstellungen automatisieren und sicherstellen, dass Ihre mobilen App-Benutzer konsistente und zuverlässige Aktualisierungen erhalten.

Wenn Sie GitLab CI/CD verwenden GitLab CI/CD Integration um die CI/CD-Automatisierung zu planen, verbinden Sie es mit 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, und GitHub Actions Integration für die Implementierungsdetails in GitHub Actions Integration.