Bitbucket Pipelines Integration
Integrate Capgo Mises à jour en direct with Bitbucket Pipelines 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 Bitbucket Pipelines integration, ensure you have:
- A Bitbucket Compte with a repository
- A Capgo Compte with an Application configured
- Node.js and npm/yarn configured in your project
Setting Up Bitbucket Pipelines
Section titled “Setting Up Bitbucket Pipelines”Step 1: Configure Repository Variables
Section titled “Step 1: Configure Repository Variables”First, set up the necessary variables in your Bitbucket repository:
- Navigate to your Bitbucket repository
- Go to Repository Paramètres → Pipelines → Repository variables
- Ajouter the following variables:
| Variable Name | Value | Secured |
|---|---|---|
CAPGO_TOKEN | Your Capgo API token | ✅ Yes |
Simple
Section titled “Simple”Basic Configuration that deploys to Production on every Pousser to the main branch:
# bitbucket-pipelines.yml - Simple Configurationimage: 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/**Advanced
Section titled “Advanced”Fonctionnalité Branch Deployments
Section titled “Fonctionnalité Branch Deployments”Déployer Fonctionnalité branches to Test Canaux for review and Test:
# Feature branch deploymentpipelines: 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/**Using 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 Bitbucket variables:
# Display your private key content (copy this output)cat .capgo_key_v2Add this content as CAPGO_PRIVATE_KEY in your Bitbucket repository variables (mark as secured), then use it in pipelines:
# 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 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 Tirer request deployments:
# bitbucket-pipelines.yml - Advanced Multi-Channel Configurationimage: 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/**Multi-Environment Pipeline
Section titled “Multi-Environment Pipeline”For complex Déploiement scenarios with staging and Production environments:
# Multi-environment pipelineimage: 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/**Branch-Based Déploiement Strategy
Section titled “Branch-Based Déploiement Strategy”Automatically Déployer different branches to appropriate Canaux:
# Dynamic channel deploymentimage: 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/**Parallel Pipeline Execution
Section titled “Parallel Pipeline Execution”Optimize Construction times with parallel steps:
# Parallel execution pipelineimage: 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 productionSécurité Best Practices
Section titled “Sécurité Best Practices”Repository Variables
Section titled “Repository Variables”- Secured Variables: Always mark API tokens as secured
- Environment Variables: Use Déploiement-specific variables when needed
- Access Control: Limit repository access to authorized team Membres
- Token Rotation: Regularly rotate your Capgo API tokens
Déploiement Environments
Section titled “Déploiement Environments”Configure Déploiement environments for better Sécurité:
# Deployment with environment restrictionspipelines: 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 productionMonitoring and Notifications
Section titled “Monitoring and Notifications”Slack Integration
Section titled “Slack Integration”Ajouter Slack notifications to your pipeline:
# Pipeline with Slack notificationspipelines: 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 fiEmail Notifications
Section titled “Email Notifications”Configure email notifications through Bitbucket’s built-in Fonctionnalités or using external services:
# 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]Dépannage
Section titled “Dépannage”Problèmes courants
Section titled “Problèmes courants”Pipeline fails with “Capgo CLI not found”:
# Debug CLI installation- step: name: Debug CLI script: - npm install -g @capgo/cli - which capgo || echo "Capgo CLI not found" - npx @capgo/cli --versionAuthentication errors:
# 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 artifacts not found:
# List build outputs- step: name: Debug 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 pipelinepipelines: 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 productionPipeline Validation
Section titled “Pipeline Validation”Activer pipeline validation to catch Configuration errors:
# Enable pipeline validationoptions: docker: true size: 2x
pipelines: branches: main: - step: name: Validate Pipeline script: - echo "Pipeline validation successful" - step: name: Build and Deploy script: # ... deployment stepsSuivant 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 Bitbucket Pipelines integration, you can automate your Capgo deployments and ensure consistent, reliable Mises à jour to your mobile Application Utilisateurs.