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. Dieser Guide zeigt dir, wie du automatisierte Build-, Test- und Deployment-Workflows einrichtest.

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

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

Richte zuerst die erforderlichen Variablen in deinem GitLab-Projekt ein:

  1. Navigiere zu deinem GitLab-Projekt
  2. Gehe zu Einstellungen → CI/CD → Variablen
  3. Füge die folgenden Variablen hinzu:
VariablennameWertGeschütztMaskiert
CAPGO_TOKENDein Capgo API Token✅ Ja✅ Ja

Basis-Konfiguration, die bei jedem Push auf den main-Branch in die Production 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

Deploye Feature Branches in Test-Channels für Reviews und Tests:

# 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 add $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

If you’re using Die Verschlüsselungsfunktion von Capgo, musst du deinen Private Key sicher in deiner CI/CD-Umgebung speichern.

Nachdem du die Encryption Keys Füge deinen privaten Key lokal zu den GitLab-Variablen hinzu:

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

Füge diesen Inhalt als CAPGO_PRIVATE_KEY in deinen GitLab-Projektvariablen hinzu (als 'protected' und 'masked' markieren), um ihn in Pipelines zu nutzen:

# 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 Deployment-Channels lesen Sie die Channels-Dokumentation.

Vollständige 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 add $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

Multi-Environment mit manueller Freigabe

Abschnitt: „Multi-Environment mit manueller Freigabe“

Für Production-Deployments mit manueller Freigabe:

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

Branch-basierte Deployment-Strategie

Abschnitt: „Branch-basierte Deployment-Strategie“

Verschiedene Branches automatisch in die passenden Channels deployen:

# 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. Sensitive Variablen markieren: Markiere API Tokens immer als geschützt und maskiert
  2. Branch-Schutz: Nutze geschützte Variablen für Production-Deployments
  3. Zugriffskontrolle: Beschränke den Zugriff auf Variablen nur auf Maintainer
  4. Regelmäßige Rotation: Rotiere 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"

Füge Slack-Benachrichtigungen zu deiner Pipeline hinzu:

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

Konfiguriere E-Mail-Benachrichtigungen in deinen GitLab-Projekteinstellungen oder nutze die 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 schlägt fehl mit „Capgo CLI not found“:

# 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 beheben:

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 GitLab CI/CD-Integration kannst du deine Capgo Deployments automatisieren und konsistente, zuverlässige Updates für deine Mobile-App-Nutzer sicherstellen.

Wenn du es nutzt GitLab CI/CD-Integration um CI/CD-Automatisierung zu planen, verbinde es mit Capgo CI/CD für den Produkt-Workflow in Capgo CI/CD, Capgo Native Builds für den Produkt-Workflow in Capgo Native Builds, Capgo Integrationen für den Produkt-Workflow in Capgo Integrations, CI/CD-Integration für die Implementierungsdetails in der CI/CD-Integration und GitHub Actions-Integration für die Implementierungsdetails in der GitHub Actions-Integration.