How to use Bitbucket Pipelines with Git
Bitbucket Pipelines provides integrated CI/CD directly in Bitbucket repositories, automating builds, tests, and deployments triggered by Git operations. As the creator of CoreUI, a widely used open-source UI library, I’ve implemented Bitbucket Pipelines in enterprise projects throughout my 25 years of development experience. The most straightforward approach is creating a bitbucket-pipelines.yml file in the repository root defining pipeline configuration. This method enables automatic testing and deployment on every Git push with Docker-based build environments.
Create bitbucket-pipelines.yml in repository root to define CI/CD pipeline configuration.
image: node:20
pipelines:
default:
- step:
name: Build and Test
caches:
- node
script:
- npm ci
- npm run lint
- npm test
- npm run build
artifacts:
- dist/**
branches:
main:
- step:
name: Build and Test
caches:
- node
script:
- npm ci
- npm run lint
- npm test
- npm run build
artifacts:
- dist/**
- step:
name: Deploy to Production
deployment: production
script:
- echo "Deploying to production..."
- npm run deploy
develop:
- step:
name: Build and Test
caches:
- node
script:
- npm ci
- npm test
pull-requests:
'**':
- step:
name: PR Validation
script:
- npm ci
- npm run lint
- npm test
Here the image field specifies the Docker image for all pipeline steps. The default pipeline runs on any branch without specific configuration. The branches section defines custom pipelines for specific branches: main runs tests then deploys to production, while develop only runs tests. The pull-requests section validates all PRs with linting and testing. Caches speed up builds by reusing node_modules. Artifacts save build outputs for subsequent deployment steps.
Best Practice Note:
This is the Bitbucket Pipelines configuration we use in CoreUI enterprise projects for automated quality assurance and controlled deployments. Use parallel steps to run tests and builds concurrently for faster pipelines, configure deployment environments with manual triggers for production safety, and leverage Bitbucket’s built-in integration with AWS, Azure, and other cloud providers for streamlined deployments.



