Bitbucket Pipelines Patterns
Core Principles
- •Fail Fast, Save Minutes - Configure all steps to fail immediately on errors. Stop parallel steps when any fails. Use
bail: 1in tests,--max-warnings=0in linting, andfail-fast: truein parallel blocks. - •Cache Aggressively - Cache dependencies, build outputs, and intermediate artifacts to minimize redundant work.
- •Run Tests in Parallel - Execute independent checks (lint, test, typecheck) concurrently for faster feedback.
- •Use Appropriate Pipeline Sizes - Match pipeline resources (1x, 2x, 4x, 8x) to workload requirements.
Quick Reference
This skill provides comprehensive Bitbucket Pipelines patterns for CI/CD workflows. Load reference files as needed:
Core Concepts:
- •fail-fast-patterns.md - Save pipeline minutes by failing early (Jest bail, Playwright maxFailures, ESLint --max-warnings=0)
- •basic-pipeline.md - Pipeline structure, steps, triggers, branches, variables, services, Pipes, image overrides
- •caching.md - Cache definitions, custom caches, cache invalidation strategies
- •deployments.md - Environment deployments, manual triggers, deployment variables
Cloud Providers:
- •gcp-deployment.md - Cloud Run, Artifact Registry, Cloud Storage, GCP authentication
- •sentry-integration.md - Sentry releases, sourcemap uploads, deployment tracking
Application Types:
- •docker.md - Docker builds, multi-stage builds, image pushing, Docker-in-Docker
- •nestjs-pipeline.md - NestJS testing, builds, GCP deployment, Sentry integration
- •frontend-pipelines.md - React, Vite, Remix, Next.js, Firebase, Playwright testing
Basic Pipeline Structure
image: node:18
definitions:
caches:
npm: ~/.npm
steps:
- step: &build-and-test
name: Build and Test
caches:
- node
script:
- npm ci
- npm run build
- npm run test
pipelines:
default:
- step: *build-and-test
branches:
main:
- step: *build-and-test
- step:
name: Deploy to Production
deployment: production
script:
- npm run deploy:prod
File Location
Always create pipeline configuration at repository root:
bitbucket-pipelines.yml
Common Patterns
Step Anchors and Reuse
definitions:
steps:
- step: &build
name: Build
script:
- npm ci
- npm run build
pipelines:
default:
- step: *build
branches:
main:
- step: *build
Parallel Execution
pipelines:
default:
- parallel:
- step:
name: Unit Tests
script:
- npm run test:unit
- step:
name: Lint
script:
- npm run lint
- step:
name: Type Check
script:
- npm run type-check
Services (Database, Docker)
definitions:
services:
mongodb:
image: mongo:7.0
environment:
MONGO_INITDB_DATABASE: test
pipelines:
default:
- step:
name: E2E Tests
services:
- mongodb
script:
- npm run test:e2e
Environment Variables
Repository Variables
Set in Bitbucket UI: Repository Settings → Pipelines → Repository variables
Secure Variables
Mark as "Secured" for sensitive data (API keys, passwords)
Pipeline Variables
definitions:
steps:
- step: &deploy
name: Deploy
script:
- export VERSION=$(git describe --tags)
- echo "Deploying $VERSION"
Best Practices
✅ Do's
- •Use caching for
node_modules, build outputs - •Employ step anchors to avoid duplication
- •Run fast checks (lint, type-check) in parallel
- •Use services for integration tests
- •Set deployment steps only for specific branches
- •Use artifacts to pass files between steps
❌ Don'ts
- •Don't commit secrets to pipeline YAML
- •Don't run expensive tests on every branch
- •Don't cache generated files that change frequently
- •Don't use large Docker images when smaller alternatives exist
- •Don't skip cache validation after dependency changes
Performance Optimization
- •Caching: Cache dependencies and build outputs
- •Parallel Steps: Run independent tasks concurrently
- •Image Size: Use slim/alpine base images
- •Conditional Execution: Use branch/tag conditions
- •Artifacts: Only pass necessary files between steps
Common Use Cases
- •Fail-Fast Patterns - Save pipeline minutes with immediate failures (Jest, Playwright, ESLint)
- •Basic Node.js Build - Install, build, test
- •Docker Build & Push - Build image and push to registry
- •Multi-Environment Deploy - Dev, staging, production
- •NestJS Complete Pipeline - Test, build, deploy NestJS apps
- •GCP Cloud Run Deploy - Deploy to Google Cloud Run with Artifact Registry
- •Sentry Release Tracking - Create releases, upload sourcemaps
- •React/Vite to Firebase - Build and deploy React apps to Firebase Hosting
- •Playwright E2E Tests - Run end-to-end tests with Playwright
Quick Tips
Maximum parallel steps: 10 steps per stage Step timeout: Default 120 minutes (configurable) Cache size limit: 1GB per cache definition Artifact retention: 14 days (configurable up to 180 days)
Reference Documentation
Performance & Optimization:
- •Fail-Fast Patterns - Save minutes by failing early (bail, maxFailures, timeouts)
- •Caching Strategies - Cache dependencies and build outputs
Core Pipelines:
- •Basic Pipeline Configuration - Syntax, structure, Pipes, image overrides
- •Deployment Patterns - Multi-environment deployments
Cloud & Services:
- •GCP Deployment - Cloud Run, Artifact Registry, authentication
- •Sentry Integration - Release tracking, sourcemaps
Application-Specific:
- •Docker Workflows - Container builds and registries
- •NestJS Pipelines - Backend API testing and deployment
- •Frontend Pipelines - React, Vite, Firebase, Playwright