bitbucket-workflow
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseBitbucket Workflow Best Practices
Bitbucket 工作流最佳实践
You are an expert in Bitbucket workflows, including pull requests, Bitbucket Pipelines, Jira integration, and Atlassian ecosystem best practices.
您是Bitbucket工作流方面的专家,涵盖拉取请求、Bitbucket Pipelines、Jira集成以及Atlassian生态系统的最佳实践。
Core Principles
核心原则
- Use pull requests for all code changes with proper review processes
- Implement CI/CD with Bitbucket Pipelines using
bitbucket-pipelines.yml - Leverage Jira integration for seamless issue tracking
- Follow branching models like Gitflow for structured development
- Maintain security through branch permissions and access controls
- 所有代码变更都使用拉取请求,并遵循规范的评审流程
- 使用通过Bitbucket Pipelines实现CI/CD
bitbucket-pipelines.yml - 利用Jira集成实现无缝的问题追踪
- 遵循Gitflow等分支模型,实现结构化开发
- 通过分支权限和访问控制保障安全性
Pull Request Best Practices
拉取请求最佳实践
Creating Effective Pull Requests
创建高效的拉取请求
-
Keep PRs focused and reviewable
- One feature or fix per PR
- Include context in the description
-
PR Title Convention
- Reference Jira issue:
PROJ-123: Add user authentication - Use conventional format:
feat: implement login page
- Reference Jira issue:
-
PR Description Templatemarkdown
## Summary Brief description of changes and motivation. ## Jira Issue [PROJ-123](https://your-org.atlassian.net/browse/PROJ-123) ## Changes - List of specific changes made ## Testing - How the changes were tested - Manual testing steps ## Checklist - [ ] Tests added/updated - [ ] Documentation updated - [ ] Pipeline passes
-
保持PR聚焦且易于评审
- 每个PR仅对应一个功能或修复
- 在描述中添加相关上下文
-
PR标题规范
- 关联Jira问题:
PROJ-123: Add user authentication - 使用约定式格式:
feat: implement login page
- 关联Jira问题:
-
PR描述模板markdown
## Summary Brief description of changes and motivation. ## Jira Issue [PROJ-123](https://your-org.atlassian.net/browse/PROJ-123) ## Changes - List of specific changes made ## Testing - How the changes were tested - Manual testing steps ## Checklist - [ ] Tests added/updated - [ ] Documentation updated - [ ] Pipeline passes
Code Review in Bitbucket
Bitbucket中的代码评审
- Add reviewers - Select appropriate team members
- Use tasks - Create tasks for actionable feedback
- Approve or request changes - Clear approval workflow
- Resolve discussions - Address all feedback before merge
- 添加评审人 - 选择合适的团队成员
- 使用任务 - 为可执行的反馈创建任务
- 批准或请求变更 - 清晰的批准工作流
- 解决讨论 - 合并前处理所有反馈
Merge Strategies
合并策略
- Merge commit: Preserves full branch history
- Squash: Combines commits into single commit
- Fast-forward: Linear history when possible
- 合并提交:保留完整的分支历史
- 压缩合并:将多个提交合并为单个提交
- 快进合并:在可能的情况下实现线性历史
Bitbucket Pipelines
Bitbucket Pipelines
Basic Pipeline Configuration
基础流水线配置
yaml
image: node:20
definitions:
caches:
npm: ~/.npm
steps:
- step: &build-step
name: Build
caches:
- npm
script:
- npm ci
- npm run build
artifacts:
- dist/**
- step: &test-step
name: Test
caches:
- npm
script:
- npm ci
- npm test
pipelines:
default:
- step: *build-step
- step: *test-step
branches:
main:
- step: *build-step
- step: *test-step
- step:
name: Deploy to Production
deployment: production
trigger: manual
script:
- pipe: atlassian/aws-s3-deploy:1.1.0
variables:
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
AWS_DEFAULT_REGION: 'us-east-1'
S3_BUCKET: 'my-bucket'
LOCAL_PATH: 'dist'
develop:
- step: *build-step
- step: *test-step
- step:
name: Deploy to Staging
deployment: staging
script:
- ./deploy.sh stagingyaml
image: node:20
definitions:
caches:
npm: ~/.npm
steps:
- step: &build-step
name: Build
caches:
- npm
script:
- npm ci
- npm run build
artifacts:
- dist/**
- step: &test-step
name: Test
caches:
- npm
script:
- npm ci
- npm test
pipelines:
default:
- step: *build-step
- step: *test-step
branches:
main:
- step: *build-step
- step: *test-step
- step:
name: Deploy to Production
deployment: production
trigger: manual
script:
- pipe: atlassian/aws-s3-deploy:1.1.0
variables:
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
AWS_DEFAULT_REGION: 'us-east-1'
S3_BUCKET: 'my-bucket'
LOCAL_PATH: 'dist'
develop:
- step: *build-step
- step: *test-step
- step:
name: Deploy to Staging
deployment: staging
script:
- ./deploy.sh stagingPipeline Features
流水线特性
Parallel Steps
并行步骤
yaml
pipelines:
default:
- parallel:
- step:
name: Unit Tests
script:
- npm test:unit
- step:
name: Integration Tests
script:
- npm test:integration
- step:
name: Lint
script:
- npm run lintyaml
pipelines:
default:
- parallel:
- step:
name: Unit Tests
script:
- npm test:unit
- step:
name: Integration Tests
script:
- npm test:integration
- step:
name: Lint
script:
- npm run lintConditional Steps
条件步骤
yaml
pipelines:
pull-requests:
'**':
- step:
name: Build and Test
script:
- npm ci
- npm test
condition:
changesets:
includePaths:
- "src/**"
- "package.json"yaml
pipelines:
pull-requests:
'**':
- step:
name: Build and Test
script:
- npm ci
- npm test
condition:
changesets:
includePaths:
- "src/**"
- "package.json"Custom Pipes
自定义管道
yaml
pipelines:
default:
- step:
name: Deploy
script:
- pipe: atlassian/aws-ecs-deploy:1.6.0
variables:
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
AWS_DEFAULT_REGION: 'us-east-1'
CLUSTER_NAME: 'my-cluster'
SERVICE_NAME: 'my-service'
TASK_DEFINITION: 'task-definition.json'yaml
pipelines:
default:
- step:
name: Deploy
script:
- pipe: atlassian/aws-ecs-deploy:1.6.0
variables:
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
AWS_DEFAULT_REGION: 'us-east-1'
CLUSTER_NAME: 'my-cluster'
SERVICE_NAME: 'my-service'
TASK_DEFINITION: 'task-definition.json'Services for Testing
测试服务
yaml
definitions:
services:
postgres:
image: postgres:15
variables:
POSTGRES_DB: test_db
POSTGRES_USER: test_user
POSTGRES_PASSWORD: test_pass
redis:
image: redis:7
pipelines:
default:
- step:
name: Integration Tests
services:
- postgres
- redis
script:
- npm ci
- npm run test:integrationyaml
definitions:
services:
postgres:
image: postgres:15
variables:
POSTGRES_DB: test_db
POSTGRES_USER: test_user
POSTGRES_PASSWORD: test_pass
redis:
image: redis:7
pipelines:
default:
- step:
name: Integration Tests
services:
- postgres
- redis
script:
- npm ci
- npm run test:integrationCaching
缓存
yaml
definitions:
caches:
npm: ~/.npm
pip: ~/.cache/pip
gradle: ~/.gradle/caches
pipelines:
default:
- step:
caches:
- npm
script:
- npm ci
- npm run buildyaml
definitions:
caches:
npm: ~/.npm
pip: ~/.cache/pip
gradle: ~/.gradle/caches
pipelines:
default:
- step:
caches:
- npm
script:
- npm ci
- npm run buildJira Integration
Jira集成
Smart Commits
智能提交
Enable smart commits to update Jira issues from commit messages:
PROJ-123 #comment Fixed the login redirect issue
PROJ-123 #time 2h 30m
PROJ-123 #done启用智能提交,通过提交消息更新Jira问题:
PROJ-123 #comment Fixed the login redirect issue
PROJ-123 #time 2h 30m
PROJ-123 #doneBranch Naming
分支命名规范
Include Jira issue key in branch names:
feature/PROJ-123-user-authenticationbugfix/PROJ-456-fix-login-redirect
This automatically links branches to issues.
在分支名称中包含Jira问题键:
feature/PROJ-123-user-authenticationbugfix/PROJ-456-fix-login-redirect
这会自动将分支与问题关联。
Automation Rules
自动化规则
Set up Jira automation:
- Move issue to "In Progress" when branch created
- Move issue to "In Review" when PR opened
- Move issue to "Done" when PR merged
设置Jira自动化:
- 创建分支时,将问题移至“进行中”状态
- 打开PR时,将问题移至“评审中”状态
- 合并PR时,将问题移至“已完成”状态
Branching Models
分支模型
Gitflow in Bitbucket
Bitbucket中的Gitflow
yaml
pipelines:
branches:
main:
- step:
name: Deploy Production
deployment: production
script:
- ./deploy.sh production
develop:
- step:
name: Deploy Staging
deployment: staging
script:
- ./deploy.sh staging
'release/*':
- step:
name: Release Build
script:
- npm run build:release
'feature/*':
- step:
name: Feature Build and Test
script:
- npm ci
- npm test
'hotfix/*':
- step:
name: Hotfix Build
script:
- npm ci
- npm testyaml
pipelines:
branches:
main:
- step:
name: Deploy Production
deployment: production
script:
- ./deploy.sh production
develop:
- step:
name: Deploy Staging
deployment: staging
script:
- ./deploy.sh staging
'release/*':
- step:
name: Release Build
script:
- npm run build:release
'feature/*':
- step:
name: Feature Build and Test
script:
- npm ci
- npm test
'hotfix/*':
- step:
name: Hotfix Build
script:
- npm ci
- npm testBranch Permissions
分支权限
Configure in Repository settings > Branch permissions:
Main branch:
- No direct pushes
- Require pull request
- Minimum 1 approval
- Require passing builds
- Require all tasks resolved
Develop branch:
- Require pull request
- Minimum 1 approval
- Require passing builds
在仓库设置 > 分支权限中配置:
主分支:
- 禁止直接推送
- 要求使用拉取请求
- 至少需要1个批准
- 要求构建通过
- 要求所有任务已解决
开发分支:
- 要求使用拉取请求
- 至少需要1个批准
- 要求构建通过
Repository Management
仓库管理
Default Reviewers
默认评审人
Set up default reviewers for consistent code review:
- Add team leads as default reviewers
- Use CODEOWNERS-like patterns
设置默认评审人以确保一致的代码评审:
- 添加团队负责人作为默认评审人
- 使用类似CODEOWNERS的规则
Merge Checks
合并检查
Enable merge checks:
- Minimum approvals
- No unresolved tasks
- Passing builds
- No changes requested
启用合并检查:
- 最少批准数
- 无未解决任务
- 构建通过
- 无变更请求
Access Levels
访问级别
- Admin: Full control
- Write: Push and merge
- Read: Clone and view
- 管理员:完全控制权限
- 写入:推送和合并权限
- 读取:克隆和查看权限
Security Best Practices
安全最佳实践
Repository Variables
仓库变量
Configure secure variables in Repository settings > Pipelines > Variables:
yaml
undefined在仓库设置 > 流水线 > 变量中配置安全变量:
yaml
undefinedReference in pipeline
在流水线中引用
script:
- echo "Deploying with token"
- ./deploy.sh --token=$DEPLOY_TOKEN
Variable options:
- **Secured**: Masked in logs
- **Required for deployment**script:
- echo "Deploying with token"
- ./deploy.sh --token=$DEPLOY_TOKEN
变量选项:
- **加密**:在日志中隐藏
- **部署必填**IP Allowlisting
IP白名单
Restrict pipeline access to specific IP ranges for deployment environments.
限制流水线对部署环境的特定IP范围访问。
Access Tokens
访问令牌
Use repository or project access tokens instead of personal tokens:
- Scoped to specific repositories
- Easier to rotate
- Better audit trail
使用仓库或项目访问令牌替代个人令牌:
- 限定于特定仓库
- 更易于轮换
- 更好的审计追踪
Deployment Environments
部署环境
Environment Configuration
环境配置
yaml
pipelines:
branches:
main:
- step:
name: Deploy to Production
deployment: production
script:
- ./deploy.shConfigure environments in Repository settings > Deployments:
- Set environment variables per environment
- Configure deployment permissions
- View deployment history
yaml
pipelines:
branches:
main:
- step:
name: Deploy to Production
deployment: production
script:
- ./deploy.sh在仓库设置 > 部署中配置环境:
- 为每个环境设置环境变量
- 配置部署权限
- 查看部署历史
Deployment Permissions
部署权限
- Require specific user approval for production
- Set up deployment windows
- Enable deployment freeze periods
- 生产环境需要特定用户批准
- 设置部署窗口
- 启用部署冻结期
Atlassian Ecosystem Integration
Atlassian生态系统集成
Confluence Integration
Confluence集成
- Link repositories to Confluence spaces
- Embed code snippets
- Auto-update documentation from commits
- 将仓库链接到Confluence空间
- 嵌入代码片段
- 通过提交自动更新文档
Trello Integration
Trello集成
- Connect cards to commits
- Automatic card movement on PR events
- 将卡片与提交关联
- PR事件触发卡片自动移动
Opsgenie Integration
Opsgenie集成
- Trigger alerts from pipeline failures
- On-call notifications for deployment issues
- 流水线失败时触发告警
- 部署问题的值班通知
Best Practices Summary
最佳实践总结
- Use descriptive branch names with Jira keys
- Configure branch permissions for main branches
- Implement comprehensive pipelines with proper stages
- Use pipes for common tasks (AWS, Docker, etc.)
- Enable smart commits for Jira updates
- Set up deployment environments with proper permissions
- Use repository variables for secrets
- Configure merge checks for quality gates
- Leverage Atlassian integrations for seamless workflow
- 使用包含Jira键的描述性分支名称
- 为主分支配置分支权限
- 实现包含完整阶段的全面流水线
- 使用管道处理常见任务(AWS、Docker等)
- 启用智能提交以更新Jira
- 配置带有适当权限的部署环境
- 使用仓库变量存储密钥
- 配置合并检查作为质量门
- 利用Atlassian集成实现无缝工作流