🪣
CI/CD & GitOps

Bitbucket Pipelines

Built-in CI/CD for Bitbucket repositories

🐧 Linux🍎 Mac🪟 Windows
Reviewed: Tested on: Kubernetes 1.29 · Terraform 1.8 · Ubuntu 22.04

Alternative — team standard for CI/CD

What is this?

Bitbucket Pipelines runs CI/CD defined in bitbucket-pipelines.yml inside your repo.

📁

Config files for Bitbucket Pipelines

Where to create or edit the main configuration — paths below match the setup steps.

  • bitbucket-pipelines.yml

    Location: Repository root (same level as README)

    Pipeline image, steps, and branches for Bitbucket CI/CD

📥

Step 01

Enable Bitbucket Pipelines

(01)Turn on Pipelines in Bitbucket

Enable Pipelines for your repository before adding the YAML file.

Linux
1# Bitbucket Cloud:
2# Repository → Repository settings → Pipelines → Settings → Enable Pipelines
3
4# Bitbucket Server/Data Center:
5# Project settings → Pipelines → Enable for repository
⚙️

Step 02

Create bitbucket-pipelines.yml

(01)Add bitbucket-pipelines.yml to repo root

Place bitbucket-pipelines.yml in the repository root — same folder as README.md. Bitbucket reads this file automatically on push.

Linux
1# From your project root (where README lives):
2cat > bitbucket-pipelines.yml << 'EOF'
3image: node:20
4pipelines:
5 default:
6 - step:
7 name: Build and test
8 script:
9 - npm ci
10 - npm test
11EOF
12
13git add bitbucket-pipelines.yml
14git commit -m "Add Bitbucket Pipelines CI"
15git push

(02)Optional — branch-specific pipelines

Use branches: or pull-requests: keys in the same bitbucket-pipelines.yml file.

Linux
1# Example snippet in bitbucket-pipelines.yml:
2# pipelines:
3# branches:
4# main:
5# - step:
6# script: [npm run deploy]
7# pull-requests:
8# '**':
9# - step:
10# script: [npm test]

Step 03

Verify Pipeline

(01)Check pipeline runs in Bitbucket

Linux
1# Bitbucket → Repository → Pipelines
2# Confirm latest commit shows a green build
🔧

Step 04

Common Problems

#1Pipeline not triggered

bitbucket-pipelines.yml must be in the repo root and Pipelines enabled.

Linux
1# Verify file at repo root (same level as README):
2ls -la bitbucket-pipelines.yml
3# Repository settings → Pipelines → Enable
4git push origin main

#2Docker service / image pull failed

Linux
1# Enable Docker in pipeline:
2# definitions:
3# services:
4# docker:
5# memory: 2048
6# Or use a pre-built image instead of docker build

📋Config templates

3 YAML templates for Bitbucket Pipelines. Copy and deploy after setup.

3 ready-to-copy templates. Expand one, copy the YAML, then run the deploy commands.

.github/workflows/ci.yml

Node.js — install, test, build Docker image, push to registry

yaml
1name: CI Pipeline
2
3on:
4 push:
5 branches: [main, develop]
6 pull_request:
7 branches: [main]
8
9env:
10 REGISTRY: ghcr.io
11 IMAGE_NAME: ${{ github.repository }}
12
13jobs:
14 build-and-test:
15 runs-on: ubuntu-latest
16 steps:
17 - uses: actions/checkout@v4
18
19 - name: Setup Node.js
20 uses: actions/setup-node@v4
21 with:
22 node-version: "20"
23 cache: "npm"
24
25 - name: Install dependencies
26 run: npm ci
27
28 - name: Run tests
29 run: npm test
30
31 - name: Build Docker image
32 run: docker build -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }} .
33
34 - name: Log in to GitHub Container Registry
35 if: github.event_name == 'push' && github.ref == 'refs/heads/main'
36 uses: docker/login-action@v3
37 with:
38 registry: ${{ env.REGISTRY }}
39 username: ${{ github.actor }}
40 password: ${{ secrets.GITHUB_TOKEN }}
41
42 - name: Push image
43 if: github.event_name == 'push' && github.ref == 'refs/heads/main'
44 run: docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}

.github/workflows/java-ci.yml

Spring Boot / Maven — compile, test, package JAR

yaml
1name: Java CI
2
3on:
4 push:
5 branches: [main]
6 pull_request:
7 branches: [main]
8
9jobs:
10 build:
11 runs-on: ubuntu-latest
12 steps:
13 - uses: actions/checkout@v4
14
15 - name: Set up JDK 21
16 uses: actions/setup-java@v4
17 with:
18 java-version: "21"
19 distribution: "temurin"
20 cache: maven
21
22 - name: Build and test
23 run: mvn -B verify
24
25 - name: Upload JAR artifact
26 uses: actions/upload-artifact@v4
27 with:
28 name: app-jar
29 path: target/*.jar
📄

Step 01

Use the Workflow

(01)Add workflow to your repo

Linux
1mkdir -p .github/workflows
2cp ci.yml .github/workflows/ci.yml
3git add .github/workflows/
4git commit -m "Add CI pipeline"
5git push origin main
6# View runs: GitHub → Actions tab

(02)Add secrets (for registry push)

Linux
1# GitHub repo → Settings → Secrets and variables → Actions
2# GITHUB_TOKEN is automatic; add DOCKERHUB_TOKEN if pushing to Docker Hub