Skip to main content

BitBucket Pipelines

Overview

BitBucket Pipelines uses a YAML-based syntax to define pipelines and actions. In Semaphore, you can use the visual workflow editor to more easily configure and preview pipelines.

Semaphore is great at modeling complex delivery workflows for fast feedback with chainable pipelines, parallel execution, and dependency management.BitBucket Pipelines require some rather creative juggling to accomplish relatively trivial tasks.

BitBucket Pipelines vs Semaphore

This section describes how to implement common BitBucket Pipelines functionalities in Semaphore.

Checkout

Checkout clones the repository in the CI environment.

Checkout is implicit in all Travis CI workflows by default.

Artifacts

Artifacts are used to store deliverables and persist files between runs.

BitBucket defines artifacts using the artifacts keyword. Artifacts are automatically available in the other steps without the need to import them manually.

pipelines:
default:
- step:
name: Build and test
image: node:10.15.0
script:
- npm install
- npm test
- npm run build
artifacts:
- dist/**
- reports/*.txt
- step:
name: Integration test
image: node:10.15.0
caches:
- node
services:
- postgres
script:
# using one of the artifacts from the previous step
- cat reports/tests.txt
- npm run integration-test

Caching

Caching speeds up the workflows by storing downloaded files in a hot cache.

BitBucket Pipelines provide predefined caches to multiple build systems and dependency managers. You can also define custom cache stores to store arbitrary data.

In this example, we cache Node dependencies:

pipelines:
default:
- step:
caches:
- node
script:
- npm install
- npm test

Language versions

We often need to activate specific language or tool versions to ensure consistent builds.

BitBucket Pipelines uses pre-built Docker versions to run commands in specific language and runtime versions.

image: node:20.17.0
pipelines:
default:
- step:
script:
- node -v

Database and services

Testing sometimes require disposable databases and services in the CI environment.

BitBucket Pipelines uses Docker images to run databases and services.

definitions:
services:
redis:
image: redis:3.2
mysql:
image: mysql:5.7
variables:
MYSQL_DATABASE: my-db
MYSQL_ROOT_PASSWORD: $password

Secrets

Secrets inject sensitive data and credentials into the workflow securely.

In BitBucket Pipelines you create hidden variables that are interpolated as environment variables at runtime.

pipelines:
default:
- step:
script:
- expr 10 / $MY_HIDDEN_NUMBER
- echo $MY_HIDDEN_NUMBER

Complete example

The following comparison shows how to build and test a Ruby on Rails project on BitBucket Pipelines and on Semaphore.

This pipeline runs steps in parallel. Each step installs Ruby and the Gems before running the test commands.

pipelines:
pull-requests:
'**':
- parallel:
- step:
name: Scan Ruby
script:
- apt-get update && apt-get install -y ruby-full
- ruby --version
- gem install bundler
- bundle install
- bin/brakeman --no-pager
- step:
name: Scan JavaScript
script:
- apt-get update && apt-get install -y ruby-full
- ruby --version
- gem install bundler
- bundle install
- bin/importmap audit
- step:
name: Lint
script:
- apt-get update && apt-get install -y ruby-full
- ruby --version
- gem install bundler
- bundle install
- bin/rubocop -f github
- step:
name: Test
script:
- apt-get update && apt-get install -y ruby-full curl libjemalloc2 libvips sqlite3
- ruby --version
- gem install bundler
- bundle install
- cp .sample.env .env
- bundle exec rake db:setup
- bundle exec rake
- bin/rails db:test:prepare test test:system
services:
- docker
env:
RAILS_ENV: test

branches:
main:
- parallel:
- step:
name: Scan Ruby
script:
- apt-get update && apt-get install -y ruby-full
- ruby --version
- gem install bundler
- bundle install
- bin/brakeman --no-pager
- step:
name: Scan JavaScript
script:
- apt-get update && apt-get install -y ruby-full
- ruby --version
- gem install bundler
- bundle install
- bin/importmap audit
- step:
name: Lint
script:
- apt-get update && apt-get install -y ruby-full
- ruby --version
- gem install bundler
- bundle install
- bin/rubocop -f github
- step:
name: Test
script:
- apt-get update && apt-get install -y ruby-full curl libjemalloc2 libvips sqlite3
- ruby --version
- gem install bundler
- bundle install
- cp .sample.env .env
- bundle exec rake db:setup
- bundle exec rake
- bin/rails db:test:prepare test test:system
env:
RAILS_ENV: test

See also