Pipelines is Bitbucket’s built-in CI. Add bitbucket-pipelines.yml to the repository root:
image: node:18
pipelines:
pull-requests:
'**':
- step:
name: Test
caches: [node]
script:
- npm ci
- npm test
branches:
main:
- step:
name: Test
caches: [node]
script: [npm ci, npm test]
- step:
name: Build and push
services: [docker]
script:
- docker build -t $REGISTRY/shop-api:$BITBUCKET_COMMIT .
- echo $REGISTRY_PASSWORD | docker login -u $REGISTRY_USER --password-stdin $REGISTRY
- docker push $REGISTRY/shop-api:$BITBUCKET_COMMIT
Set REGISTRY, REGISTRY_USER and REGISTRY_PASSWORD as secured repository variables, not in the file. Tagging with $BITBUCKET_COMMIT makes each image traceable to a commit.
The Free plan includes a limited number of build minutes each month, so use caches, fail fast, and add condition: changesets to skip steps when unrelated files change. Add a manual trigger: manual step for production deploys.