Bitbucket
バージョン管理ツール
Bitbucket
概要
Bitbucketは、Atlassianが提供するGitベースのソースコード管理・ホスティングサービスです。Jira、Confluence、Trelloといった他のAtlassianツールとの強力な統合機能により、企業での統合開発環境構築に最適化されています。Gitリポジトリの管理、プルリクエストベースのコードレビュー、Bitbucket Pipelinesを使用したCI/CD機能、詳細なアクセス権限管理などを提供し、特に企業でのセキュリティ要件と生産性向上を両立させた開発ワークフローを実現します。
詳細
Bitbucket 2025年版は、5%のマーケットシェアを持つ企業向けGitホスティングプラットフォームとして確固たる地位を築いています。AtlassianエコシステムのコアコンポーネントとしてJira Software、Confluence、Bamboo、HipChatなどとシームレスに連携し、エンドツーエンドの開発プロセスを統合管理できます。優れたセキュリティ機能として、ブランチ権限、マージチェック、IP制限、2段階認証、監査ログ機能を提供。Bitbucket Pipelinesによる内蔵CI/CD機能により、Dockerコンテナベースの自動ビルド・テスト・デプロイメントを実装可能です。
主な特徴
- Atlassianエコシステム統合: Jira、Confluence、Trelloとの完全統合
- 企業向けセキュリティ: ブランチ権限、IP制限、監査ログ機能
- Bitbucket Pipelines: YAML設定によるCI/CDパイプライン
- プルリクエスト機能: インラインコメント、承認ワークフロー
- Smart Mirrors: 分散チーム向けのリポジトリミラーリング
- Code Search: 高度なコード検索とナビゲーション機能
メリット・デメリット
メリット
- 5%のマーケットシェアでAtlassianエコシステムの中核として重要な位置
- Jira課題との双方向連携によるトレーサビリティの確保
- 企業レベルのセキュリティ機能と詳細なアクセス権限管理
- Bitbucket Pipelinesによる統合されたCI/CD環境
- 無料プランでも最大5ユーザーまで利用可能(プライベートリポジトリ含む)
- REST API、WebhookによるMicrosoftエコシステムやサードパーティツール統合
デメリット
- GitHub、GitLabと比較して機能更新の頻度が低い
- 大規模なオープンソースコミュニティの支持はGitHubに劣る
- Atlassianツール以外との連携はサードパーティ依存
- ユーザーインターフェースの学習コストがやや高い
- 高度な機能は有料プランでのみ利用可能
- Bitbucket Pipelinesのビルド時間制限(無料プランでは月50分)
参考ページ
書き方の例
アカウント設定とリポジトリ作成
# SSH キーを設定
ssh-keygen -t ed25519 -C "[email protected]"
cat ~/.ssh/id_ed25519.pub # 公開鍵をBitbucketに登録
# 新しいリポジトリをクローン
git clone [email protected]:username/repository-name.git
cd repository-name
# 初期設定
git config user.name "Your Name"
git config user.email "[email protected]"
# 最初のコミット
echo "# Project Name" > README.md
git add README.md
git commit -m "Initial commit"
git push -u origin main
Bitbucket Pipelines設定(bitbucket-pipelines.yml)
# 基本的なNode.jsプロジェクトのCI/CD
image: node:18
pipelines:
default:
- step:
name: Build and Test
caches:
- node
script:
- npm ci
- npm run test
- npm run build
artifacts:
- dist/**
branches:
main:
- step:
name: Build and Test
caches:
- node
script:
- npm ci
- npm run test
- npm run build
artifacts:
- dist/**
- step:
name: Deploy to Production
deployment: production
script:
- echo "Deploying to production..."
- npm run deploy:prod
develop:
- step:
name: Build and Test
caches:
- node
script:
- npm ci
- npm run test
- npm run build
- step:
name: Deploy to Staging
deployment: staging
script:
- echo "Deploying to staging..."
- npm run deploy:staging
pull-requests:
'**':
- step:
name: Test Pull Request
caches:
- node
script:
- npm ci
- npm run test
- npm run lint
Dockerベースのマルチステップパイプライン
# Docker環境での複数言語対応
image: atlassian/default-image:3
pipelines:
default:
- parallel:
- step:
name: Frontend Tests
image: node:18
caches:
- node
script:
- cd frontend
- npm ci
- npm run test:coverage
- npm run build
artifacts:
- frontend/dist/**
- step:
name: Backend Tests
image: python:3.11
caches:
- pip
script:
- cd backend
- pip install -r requirements.txt
- python -m pytest --cov=./ --cov-report=xml
- python manage.py collectstatic --noinput
artifacts:
- backend/staticfiles/**
- step:
name: Integration Tests
image: docker:20.10.16
services:
- docker
script:
- docker-compose -f docker-compose.test.yml up --build --abort-on-container-exit
- docker-compose -f docker-compose.test.yml down
definitions:
caches:
node: frontend/node_modules
pip: ~/.cache/pip
services:
docker:
memory: 3072
プルリクエストワークフロー
# 機能ブランチの作成と開発
git checkout -b feature/add-user-authentication
git push -u origin feature/add-user-authentication
# 開発とコミット
git add .
git commit -m "feat: implement user login functionality
- Add login form component
- Implement JWT authentication
- Add user session management
- Update navigation to show logout option
Closes #USER-123"
# プルリクエスト作成前の最新化
git fetch origin
git rebase origin/main
# プッシュとプルリクエスト作成
git push --force-with-lease origin feature/add-user-authentication
# Bitbucket WebUIでプルリクエスト作成後
# または CLI使用
curl -u username:app_password \
-H "Content-Type: application/json" \
-X POST \
https://api.bitbucket.org/2.0/repositories/username/repo/pullrequests \
-d '{
"title": "Add user authentication functionality",
"description": "Implements user login/logout with JWT authentication",
"source": {"branch": {"name": "feature/add-user-authentication"}},
"destination": {"branch": {"name": "main"}},
"reviewers": [{"username": "reviewer1"}, {"username": "reviewer2"}]
}'
Jira連携の設定
# コミットメッセージでJira課題を自動更新
git commit -m "USER-123 #resolve #time 2h #comment Implemented user authentication
This resolves the user authentication requirement by:
- Adding secure JWT token handling
- Implementing proper session management
- Adding comprehensive error handling"
# ブランチ名でJira課題と連携
git checkout -b feature/USER-123-user-authentication
git push -u origin feature/USER-123-user-authentication
# プルリクエストタイトルで自動連携
# "USER-123: Add user authentication functionality"
Webhookとカスタム統合
# Webhook設定(REST API使用)
curl -u username:app_password \
-H "Content-Type: application/json" \
-X POST \
https://api.bitbucket.org/2.0/repositories/username/repo/hooks \
-d '{
"description": "Slack notification webhook",
"url": "https://hooks.slack.com/services/YOUR/SLACK/WEBHOOK",
"active": true,
"events": [
"repo:push",
"pullrequest:created",
"pullrequest:updated",
"pullrequest:approved",
"pullrequest:merged"
]
}'
# 環境変数を使用したセキュアな設定
curl -u $BITBUCKET_USERNAME:$BITBUCKET_APP_PASSWORD \
-H "Content-Type: application/json" \
-X GET \
https://api.bitbucket.org/2.0/repositories/username/repo/pipelines_config/variables/
ブランチ権限とマージチェック設定
# ブランチ権限設定(API経由)
curl -u username:app_password \
-H "Content-Type: application/json" \
-X POST \
https://api.bitbucket.org/2.0/repositories/username/repo/branch-restrictions \
-d '{
"kind": "push",
"pattern": "main",
"users": [],
"groups": ["administrators"],
"value": null
}'
# マージチェック設定(最小承認数)
curl -u username:app_password \
-H "Content-Type: application/json" \
-X POST \
https://api.bitbucket.org/2.0/repositories/username/repo/branch-restrictions \
-d '{
"kind": "require_approvals_to_merge",
"pattern": "main",
"value": 2
}'
高度なパイプライン設定
# 環境別デプロイメントとマニュアル承認
image: atlassian/default-image:3
pipelines:
branches:
main:
- step:
name: Build and Test
script:
- echo "Building application..."
- ./scripts/build.sh
- ./scripts/test.sh
- step:
name: Deploy to Staging
deployment: staging
script:
- echo "Deploying to staging environment..."
- ./scripts/deploy.sh staging
after-script:
- ./scripts/smoke-tests.sh staging
- step:
name: Manual Approval for Production
script:
- echo "Waiting for manual approval..."
trigger: manual
- step:
name: Deploy to Production
deployment: production
script:
- echo "Deploying to production environment..."
- ./scripts/deploy.sh production
after-script:
- ./scripts/smoke-tests.sh production
- ./scripts/notify-stakeholders.sh
definitions:
services:
redis:
image: redis:7-alpine
postgres:
image: postgres:15
variables:
POSTGRES_DB: testdb
POSTGRES_USER: testuser
POSTGRES_PASSWORD: $DATABASE_PASSWORD