GitLab CI/CD Integration
Integrate Capgo Mises à jour en direct with GitLab CI/CD to automatically Déployer your Application Mises à jour whenever you Pousser code changes. This Guide covers setting up automated builds, Test, and Déploiement workflows.
Prerequisites
Section titled “Prerequisites”Before setting up GitLab CI/CD integration, ensure you have:
- A GitLab Compte with a project repository
- A Capgo Compte with an Application configured
- Node.js and npm/yarn configured in your project
Setting Up GitLab CI/CD
Section titled “Setting Up GitLab CI/CD”Step 1: Configure Environment Variables
Section titled “Step 1: Configure Environment Variables”First, set up the necessary variables in your GitLab project:
- Navigate to your GitLab project
- Go to Paramètres → CI/CD → Variables
- Ajouter the following variables:
| Variable Name | Value | Protected | Masked |
|---|---|---|---|
CAPGO_TOKEN | Your Capgo API token | ✅ Yes | ✅ Yes |
Simple
Section titled “Simple”Basic Configuration that deploys to Production on every Pousser to the main branch:
# .gitlab-ci.yml - Simple Configurationimage: 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: - mainAdvanced
Section titled “Advanced”Fonctionnalité Branch Deployments
Section titled “Fonctionnalité Branch Deployments”Déployer Fonctionnalité branches to Test Canaux for review and Test:
# Feature branch deploymentdeploy_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_NAMEUsing Chiffrement
Section titled “Using Chiffrement”If you’re using [Capgo’s Chiffrement Fonctionnalité](/docs/live-Mises à jour/Chiffrement/), you’ll need to store your private key securely in your CI/CD environment.
After [setting up Chiffrement keys](/docs/live-Mises à jour/Chiffrement/#setting-up-Chiffrement) locally, Ajouter your private key to GitLab variables:
# Display your private key content (copy this output)cat .capgo_key_v2Add this content as CAPGO_PRIVATE_KEY in your GitLab project variables (mark as protected and masked), then use it in pipelines:
# Deploy with encryptiondeploy_production: script: - npm install -g @capgo/cli - npx @capgo/cli bundle upload --apikey $CAPGO_TOKEN --key-data-v2 "$CAPGO_PRIVATE_KEY" --channel productionMulti-Canal Configuration
Section titled “Multi-Canal Configuration”For comprehensive Information À propos setting up and managing multiple Déploiement Canaux, see the [Canaux Documentation](/docs/live-Mises à jour/Canaux/).
Terminé Configuration with multiple environments and merge request deployments:
# .gitlab-ci.yml - Advanced Multi-Channel Configurationimage: node:22
stages: - build - deploy
variables: npm_config_cache: "$CI_PROJECT_DIR/.npm"
# Build stagebuild: stage: build script: - npm ci - npm run test - npm run build artifacts: paths: - dist/ expire_in: 24 hours
# Deploy to development channeldeploy_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 channelsdeploy_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 closedcleanup_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 stagingdeploy_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 productiondeploy_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: productionMulti-Environment with Manual Approval
Section titled “Multi-Environment with Manual Approval”For Production deployments requiring manual approval:
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: productionBranch-Based Déploiement Strategy
Section titled “Branch-Based Déploiement Strategy”Déployer different branches to appropriate Canaux automatically:
# Dynamic channel deployment based on branchdeploy: 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: $CHANNELSécurité Best Practices
Section titled “Sécurité Best Practices”Protected Variables
Section titled “Protected Variables”- Mark Sensitive Variables: Always mark API tokens as protected and masked
- Branch Protection: Use protected variables for Production deployments
- Access Control: Limit variable access to maintainers only
- Regular Rotation: Rotate API tokens regularly
Secure Pipeline Configuration
Section titled “Secure Pipeline Configuration”# Use protected variables for productiondeploy_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"Monitoring and Notifications
Section titled “Monitoring and Notifications”Slack Integration
Section titled “Slack Integration”Ajouter Slack notifications to your pipeline:
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_failureEmail Notifications
Section titled “Email Notifications”Configure email notifications in your GitLab project Paramètres or use the 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: alwaysDépannage
Section titled “Dépannage”Problèmes courants
Section titled “Problèmes courants”Pipeline fails with “Capgo CLI not found”:
# Debug CLI installationdebug_cli: script: - npm install -g @capgo/cli - which capgo || echo "Capgo CLI not found" - npx @capgo/cli --versionAuthentication errors:
# Verify token configurationdebug_auth: script: - | if [ -z "$CAPGO_TOKEN" ]; then echo "CAPGO_TOKEN is not set" exit 1 fi echo "Token length: ${#CAPGO_TOKEN}"Build artifacts not found:
# List build outputsdebug_build: script: - ls -la dist/ - find dist/ -type f -name "*.js" -o -name "*.html"Débogage Pipeline
Section titled “Débogage Pipeline”Ajouter Débogage Information to troubleshoot issues:
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: - branchesSuivant Steps
Section titled “Suivant Steps”- Learn À propos [Canaux](/docs/live-Mises à jour/Canaux/) to manage different Déploiement environments
- Explore [Custom Storage](/docs/live-Mises à jour/custom-storage/) for advanced Déploiement scenarios
- Set up [Chiffrement](/docs/live-Mises à jour/Chiffrement/) for secure deployments
- Configure [Mise à jour Behavior](/docs/live-Mises à jour/Mise à jour-behavior/) to customize how Mises à jour are applied
With GitLab CI/CD integration, you can automate your Capgo deployments and ensure consistent, reliable Mises à jour to your mobile Application Utilisateurs.