Pipeline Basics
How It Works
bitbucket-pipelines.ymlConfig file in repo root
Docker containersEach step runs in its own container
TriggersPush, PR, tag, schedule, or manual
Build minutesQuota depends on plan tier
Enabling Pipelines
# Repository Settings → Pipelines → Enable # Add bitbucket-pipelines.yml to repo root # First push triggers the pipeline
bitbucket-pipelines.yml
Minimal Config
image: node:20 pipelines: default: - step: script: - npm install - npm test
Branch-Specific Pipelines
pipelines: branches: main: - step: script: - npm run build - npm run deploy
Tag & Pull Request Pipelines
pipelines: tags: 'v*': - step: script: - npm run release pull-requests: '**': - step: script: - npm test
Steps
Step Options
nameDisplay name for the step
imageOverride global Docker image
scriptList of shell commands to run
size1x (4GB) or 2x (8GB) memory
max-timeTimeout in minutes (default 120)
triggermanual for manual-only steps
Parallel Steps
- parallel: - step: name: "Lint" script: - npm run lint - step: name: "Test" script: - npm test
Manual Step
- step: name: "Deploy to Production" trigger: manual script: - ./deploy.sh prod
Variables
Variable Types
Repository variablesSettings → Pipelines → Variables
Deployment variablesScoped to a deployment environment
Secured variablesEncrypted, masked in logs
Pipeline variablesDefined inline in YAML
Using Variables
pipelines: default: - step: script: - echo $MY_VAR - docker login -u $DOCKER_USER -p $DOCKER_PASS
Built-in Variables
$BITBUCKET_COMMITFull commit SHA
$BITBUCKET_BRANCHBranch name
$BITBUCKET_TAGTag name (tag pipelines)
$BITBUCKET_BUILD_NUMBERIncrementing build number
$BITBUCKET_REPO_SLUGRepository slug
Caching
Predefined Caches
- step: caches: - node # ~/.npm - pip # ~/.cache/pip - docker # Docker layer cache script: - npm install - npm test
Custom Cache
definitions: caches: gradle: ~/.gradle/caches mylibs: vendor/libs pipelines: default: - step: caches: - gradle script: - ./gradlew build
Cache Behavior
DurationCaches expire after 7 days
ScopeShared across all pipelines in repo
ClearPipelines → Caches → Delete
Artifacts
Passing Files Between Steps
- step: name: "Build" script: - npm run build artifacts: - dist/** - step: name: "Deploy" script: - ls dist/ # artifacts available - ./deploy.sh
Artifact Options
artifactsGlob patterns for files to pass
DownloadAvailable in subsequent steps automatically
Max size1 GB per step
RetentionAvailable for 14 days after build
Deployments
Deployment Environments
- step: name: "Deploy Staging" deployment: staging script: - ./deploy.sh staging - step: name: "Deploy Production" deployment: production trigger: manual script: - ./deploy.sh prod
Environment Types
testTesting environment
stagingPre-production environment
productionLive environment, tracked in dashboard
Common Patterns
Docker Build & Push
- step: services: - docker script: - docker build -t myapp:$BITBUCKET_COMMIT . - docker login -u $DOCKER_USER -p $DOCKER_PASS - docker push myapp:$BITBUCKET_COMMIT
Service Containers
definitions: services: postgres: image: postgres:16 variables: POSTGRES_DB: testdb POSTGRES_PASSWORD: secret pipelines: default: - step: services: - postgres script: - npm test
Conditional Step with Pipe
- step: name: "Deploy to S3" script: - pipe: atlassian/aws-s3-deploy:1.1.0 variables: AWS_ACCESS_KEY_ID: $AWS_KEY AWS_SECRET_ACCESS_KEY: $AWS_SECRET S3_BUCKET: my-bucket LOCAL_PATH: dist/